Skip to content

Instantly share code, notes, and snippets.

@dylanerichards
Last active September 28, 2016 20:36
Show Gist options
  • Save dylanerichards/4ddd3c412de5dfe3f3bde4c6cf063ad8 to your computer and use it in GitHub Desktop.
Save dylanerichards/4ddd3c412de5dfe3f3bde4c6cf063ad8 to your computer and use it in GitHub Desktop.
JS Code Challenges
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));
function transmix(num) {
return num.toString().split("").reverse().map(function(string) {
return parseInt(string);
});
};
console.log(transmix(90210));
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