Skip to content

Instantly share code, notes, and snippets.

@aseevia
Last active July 6, 2018 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aseevia/0d314c14e534d866470d8f52e1882f7d to your computer and use it in GitHub Desktop.
Save aseevia/0d314c14e534d866470d8f52e1882f7d to your computer and use it in GitHub Desktop.
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];
}
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]] ;
}
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