Created
September 14, 2020 15:03
-
-
Save benschac/101b184515fd3d2660478313ca868856 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 fibsLike(arr) { | |
let longest = 0; | |
for (let q = 0; q < arr.length; q++) { | |
let acc = new Set([]); | |
for (let i = q; i < arr.length; i++) { | |
for (let j = i + 1; j < arr.length; j++) { | |
let slow = arr[i]; | |
let fast = arr[j]; | |
let idx = arr.indexOf(slow + fast); | |
if (idx > -1 && idx > i) { | |
acc.add(slow); | |
acc.add(fast); | |
acc.add(arr[idx]); | |
i = idx; | |
j = idx; | |
} | |
} | |
} | |
if (longest < acc.size) { | |
longest = acc.size; | |
} | |
} | |
return longest; | |
} | |
console.log(fibsLike([1, 3, 5])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment