// YOUR CODE
function evenAndOdd(array){
let newarray =[[],[]]
for(let i=0; i<array.length; i++){
if(array[i]%2===0){
newarray[0].push(array[i])
}
else{
newarray[1].push(array[i])
}
}
return newarray
}
console.log(evenAndOdd(1,2,3,4,5,6))
// DO NOT EDIT BELOW
module.exports = evenAndOdd;
How do I fix this?
Im a beginner currently learning to code in javascript and am not sure how to fix this. Please try to use the same terms I've used here as I've not covered everything. How do I use an array as an argument in a function? I tried doing let array=[] and also evenAndOdd([]) but that doesnt work. And have I coded the part to put the even numbers in one array and the odd numbers in the other correctly. This is the question that I'm trying to answer:
Define a function, evenAndOdd, that accepts an array.
evenAndOdd should return a new array containing two smaller arrays:
The first element in the new array should be an array with all of the even numbers from the original array.
The second element in the new array should be an array with all of the odd numbers from the original array.