I have an array and I want to double each odd number as well as return a new array with the newly doubled numbers. For some reason, the values won't double; here is my code.
function doubleOddNumbers(arr) {
return arr.filter(function(value) {
if(value%2 !== 0) {
return value * 2
}
})
}
When I look at my results in the console I continue to get the same odd numbers instead of them being doubled e.g. [1,2,3,4] will return [1,3] instead of [2, 6].
.map()to transform/map those numbers. You should returntruefrom the filter method when you want to keep an item, andfalsewhen you want to remove the item.