I am trying to use the following code with map or filter methods
is it possible to do that:
function doubleOddNumbers(numbers) {
const newNumbers = [];
for (let i = 0; i < numbers.length; i++) {
if (numbers[i] % 2 !== 0) {
newNumbers.push(numbers[i] * 2);
}
}
return newNumbers;
}
const myNumbers = [1, 2, 3, 4];
console.log(doubleOddNumbers(myNumbers);
// Do not change or remove anything below this line
module.exports = {
myNumbers,
doubleOddNumbers,
};
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…