Sum of numbers in the Kth level of a Fibonacci triangle | Function to return the nth Fibonacci number ; Function to return the required sum of the array ; Using our deduced result ; Function to return the sum of fibonacci in the Kth array ; Count of fibonacci which are in the arrays from 1 to k - 1 ; Driver code
function fib ( n ) { var phi = ( 1 + Math . sqrt ( 5 ) ) / 2 ; return parseInt ( Math . round ( Math . pow ( phi , n ) / Math . sqrt ( 5 ) ) ) ; } function calculateSum ( l , r ) { var sum = fib ( r + 2 ) - fib ( l + 1 ) ; return sum ; } function sumFibonacci ( k ) { var l = ( k * ( k - 1 ) ) / 2 ; var r = l + k ; var sum = calculateSum ( l , r - 1 ) ; return sum ; } var k = 3 ; document . write ( sumFibonacci ( k ) ) ;