Last active
September 28, 2016 20:36
-
-
Save dylanerichards/4ddd3c412de5dfe3f3bde4c6cf063ad8 to your computer and use it in GitHub Desktop.
JS Code Challenges
This file contains 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 characters
function stringy(num) { | |
var result = [1]; | |
if (num == 1) { return result; }; | |
for(i = 0; i < num; i++) { | |
var lastElement = result[result.length - 1]; | |
lastElement == 0 ? result.push(1) : result.push(0); | |
} | |
return result.join("").substring(0, num); | |
}; | |
console.log(stringy(4)); |
This file contains 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 characters
function transmix(num) { | |
return num.toString().split("").reverse().map(function(string) { | |
return parseInt(string); | |
}); | |
}; | |
console.log(transmix(90210)); |
This file contains 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 characters
function fibonacci(max) { | |
fibs = [0, 1] | |
for(var i = 0; i < max - 2; i++) { | |
last = fibs[fibs.length - 1] | |
secToLast = fibs[fibs.length - 2] | |
next = last + secToLast | |
fibs.push(next) | |
} | |
return fibs | |
} | |
console.log(fibonacci(3)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment