summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarol (Nichols || Goulding) <carol.nichols@gmail.com>2017-03-19 10:02:51 -0400
committerGitHub <noreply@github.com>2017-03-19 10:02:51 -0400
commit2ee6e22e5ca2da45a38e96d3c61396fe264084cd (patch)
tree0becc379df46629865efa4ce47d4b9b97e9cd075
parent4cd095466b0ea243453de7531900bf7faa5b1b19 (diff)
parente0274e07d0c6bf7c65ceb694176fce233f812181 (diff)
Merge pull request #56 from mwilli20/patch-1
Create iterators4.rs
-rw-r--r--standard_library_types/iterators4.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/standard_library_types/iterators4.rs b/standard_library_types/iterators4.rs
new file mode 100644
index 0000000..e758bd1
--- /dev/null
+++ b/standard_library_types/iterators4.rs
@@ -0,0 +1,59 @@
+pub fn factorial(num: u64) -> u64 {
+ // Complete this function to return factorial of num
+ // Do not use:
+ // - return
+ // For extra fun don't use:
+ // - imperative style loops (for, while)
+ // - additional variables
+ // For the most fun don't use:
+ // - recursion
+ // Scroll down for hints.
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn factorial_of_1() {
+ assert_eq!(1, factorial(1));
+ }
+ #[test]
+ fn factorial_of_2() {
+ assert_eq!(2, factorial(2));
+ }
+
+ #[test]
+ fn factorial_of_4() {
+ assert_eq!(24, factorial(4));
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+// In an imperative language you might write a for loop to iterate through
+// multiply the values into a mutable variable. Or you might write code more
+// functionally with recursion and a match clause. But you can also use ranges
+// and iterators to solve this in rust.