How to use an if statement in an array map function?
Here is how my example code currently looks: https://jsfiddle.net/pwb7t5hf/10/
const sizes = [
36,37,38,39,40
]
const allSizes = sizes.map(size => (
if(size > 38) {
return size++;
}
else {
return size;
}
));
console.log(allSizes);
The debugger gives me bag that if is an unexpected token.
Would appreciate some help :)
PS: I am aware, that this is not a good functional way but I am a bit stuck how to do that the functional way :). So I thought I would solve it, for now, this way.
Posted Jul 24, 2018, 5:06 PM UTC · edited
Wrap the function body in curly braces, not parenthesis.