How do I get Odd numbers 1-100 ?
Discussion posts and replies are publicly visible
Hi, See below code.
a!forEach( items: enumerate(100)+1, expression: if( mod(fv!item,2)=0, {}, fv!item ) )
Out of context tho, but are these some assignment questions that you have to complete and submit?
looks like interview questions.
If you're looking for pure performance then this is a better option. For 100 numbers though the difference is essentially non-existent.
where( apply( fn!mod, 1 + enumerate(100000), 2 ) <> 0 )
a!localVariables( local!start:1, local!end:100, local!dif: local!end-local!start, local!list:odd(enumerate(local!dif)+local!start), union( local!list, local!list ) )
a!localVariables( local!values : a!forEach( items: enumerate(100)+1, expression: if( mod(fv!item,2) = 0, 0, odd(fv!item) )), local!odds : remove(local!values,wherecontains({null(),0},local!values)), local!odds)