Created
April 4, 2017 00:13
-
-
Save HeyMarcy/e8eafe43c2e854c2b20aa7f11d511e37 to your computer and use it in GitHub Desktop.
Revisions
-
HeyMarcy created this gist
Apr 4, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ // Count Sheep var countSheep = function(n){ if (n === 0){ return; } console.log("Another sheep jumps over the fence " +n); countSheep(n-1) } countSheep(12); ////////////////////////////////////////////// // Double Arr // Write a program that takes an array as input which contains an unknown set of numbers, // and output an array which doubles the values of each item in that array. function doubleArr(arr){ if(!arr.length){ return []; } return [ arr[0]*2, ...doubleArr(arr.slice(1)) ]; } console.log(doubleArr([1,2,3,4,5,6])) ////////////////////////////////////////////// // reverses a string. // Take a string as input, reverse the string, and return the new string. reverse = (string) => { if (!string.length){ return ""; } const lastLtr = string.slice(-1); console.log(lastLtr) console.log(string.slice(0,string.length-1)) return lastLtr + reverse(string.slice(0,string.length-1)) } console.log(reverse ("ABCDEFG")); ////////////////////////////////////////////// // Triangle Number const f = function(n) { if (n === 1) { return 1; } console.log(n) ////////////////////////////////////////////// // String Splitter function split(str) { if(!str.length) { return ""; } return str[0] + split(str.slice(1)); } console.log(split("hello")) return n + f( n - 1); }; console.log(f(4)); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,59 @@ function split(str) { if(!str.length) { return ""; } return str[0] + split(str.slice(1)); } //Exercise 5 - String Splitter function split(str) { if(!str.length) { return; } return str[0] + "-" + split(str.slice(1)); } console.log(split("hello")) //Binary function binary(num) { if (num < 2){ return num; } else { return binary(Math.floor(num/2)).toString() + (num % 2).toString(); } } binary(37); //Factorial var factorial = x => { if (x === 0) { return 1; } return x * factorial(x-1); } console.log(factorial(3)) //Fibonacci vvar fibonacci = x => { if (x <= 1) { return 1 } return fibonacci(x - 1) + fibonacci(x - 2); } for (i=0; i<20; i++){ console.log(fibonacci(i)); }