Newman | Function to find the n - th element ; Declare array to store sequence ; Driver Code
function sequence ( n ) { let i ; let f = [ ] ; f [ 0 ] = 0 ; f [ 1 ] = 1 ; f [ 2 ] = 1 ; for ( let i = 3 ; i <= n ; i ++ ) f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ; return f [ n ] ; } let n = 10 ; document . write ( sequence ( n ) ) ;