Last active
July 6, 2018 08:54
-
-
Save aseevia/0d314c14e534d866470d8f52e1882f7d to your computer and use it in GitHub Desktop.
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 getFibo(num) { | |
let row = [1, 1]; | |
for (let i = 2; i < num; i++) { | |
row.push(row[i-1] + row[i-2]); | |
} | |
return row[row.length-1]; | |
} |
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 getPrev2Fibos(num) { | |
let row = [1, 1]; | |
for (let i = 2;;i++) { | |
let n = row[i-1] + row[i-2]; | |
row.push(n); | |
if (n >= num) { | |
break; | |
} | |
} | |
return [row[row.length-2], row[row.length-3]] ; | |
} |
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 isPalindrome(input) { | |
if (input.length == 1) return true; | |
let odd = input.length % 2; | |
let first = input.slice(0, Math.floor(input.length/2)); | |
let last = input.slice(Math.floor(input.length/2)+odd); | |
last = last.split("").reverse().join(""); | |
return (first == last); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment