9
function that accepts a parameter and is a numerical matrix and will cross the array and if the element is even will push to the an array "even" and if it is odd will push to the array "odd"
I tried to do it this way below but nothing worked. What would be the right solution?
function PickIt(array) {
var array = [1, 2, 3, 4, 5];
var par = [];
var impar = [];
for (var i = 0; i < array.length; i++) {
if (array[i] % 2 === 0) {
return par.push(array[i]);
} else {
return impar.push(array[i]);
}
}
}
PickIt();
I’m surprised no one suggested using the foreach. It gets so simple and readable.
– Máttheus Spoo
Was any of the answer helpful? Don’t forget to choose one and mark it so it can be used if someone has a similar question!
– Sorack