Sum of the first N terms of XOR Fibonacci series | Function to calculate the sum of the first N terms of XOR Fibonacci Series ; Base Case ; Stores the sum of the first N terms ; Iterate from [ 0 , n - 3 ] ; Store XOR of last 2 elements ; Update sum ; Update the first element ; Update the second element ; Prlet the const sum ; Driver Code ; Function Call
function findSum ( a , b , n ) { if ( n == 1 ) { document . write ( a ) ; return ; } let s = a + b ; for ( i = 0 ; i < n - 2 ; i ++ ) { let x = a ^ b ; s += x ; a = b ; b = x ; } document . write ( s ) ; } let a = 2 , b = 5 , N = 8 ; findSum ( a , b , N ) ;