PLEASE HELP ME SOLVE MY PROBLEM (SOLVED) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

PLEASE HELP ME SOLVE MY PROBLEM (SOLVED)

How to push an element array to variable with for.. of loop, https://code.sololearn.com/WS3tvhNtWl8E/?ref=app

27th May 2021, 5:15 AM
hafidz ridwan cahya
hafidz ridwan cahya - avatar
5 Answers
+ 4
https://code.sololearn.com/WElXdtf8oCF2/?ref=app Explanation : for of loop to iterate over all elements of number, after each itration we check that (i%2) , i%2 will give eighter 1 or 0 , if it's 0 it means it's even and if it's 1 means it's odd and in javascript 0 is false and other numbers are true in if condition. So if i%2 is giving one means it's odd and 1 means true then it will push that element in odd.
27th May 2021, 5:27 AM
Abhiyantā
Abhiyantā - avatar
0
you can also use filter() array method to do it onelined, as well as checking for oddity with using bitwise & operator: let odd = number.filter(v => v&1); & operator acts as a binary mask, returning only part of number wich have bits sets: 0 & 0 = 0 0 & 1 = 0 1 & 0 = 0 1 & 1 = 1 so n & 1 return left most bit of it: 0 or 1, wich means number is odd if 1 else even ^^
27th May 2021, 10:30 AM
visph
visph - avatar
0
//print "JS is fun" console.log("JS is fun")
26th Sep 2021, 7:09 AM
GUNASEKARA H.G.D.A.P. (CST18022)
GUNASEKARA H.G.D.A.P. (CST18022) - avatar
- 3
Write a program to print "JS is fun". Note that the sentence starts with capital letters. Hint Use console.log() function.
29th May 2021, 1:34 AM
Jhojit Caisip Fajardo
- 6
Write a program to print "JS is fun". Note that the sentence starts with capital letters. Hint Use console.log() function.
29th Jun 2021, 2:19 PM
Innat Ally
Innat Ally - avatar