// Write a function that takes an array of integers as input. // For each integer, output the next fibonacci number. // Solution that work both cpu and memory efficient are appreciated. // Fibonacci number of Fn is defined by: // Fn = Fn-1 + Fn-2 // F1 = 1, F2 = 1 // For example: // nextFibonacci([1,22,9]) // Output: // 2 // 34 // 13 function nextFibonacci(array) { const sortArray = array.slice().sort((a, b) => a < b) let fibArray = [1, 1]; let i = 2; let fibCalculate = 0; while(fibCalculate < sortArray[0]) { fibCalculate = fibArray[i - 2] + fibArray[i - 1]; fibArray.push(fibCalculate); i++; } for (let j = 0;j < array.length; j++) { for (let k = 0;k < fibArray.length; k++) { if (array[j] < fibArray[k]) { console.log(fibArray[k]); break; } } } } console.log('Input is 1, 22, 9, 150'); console.log('Answer is 2, 34, 13, 233'); nextFibonacci([1, 22, 9, 150]) // 2, 34, 13, 233