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