var numbers = [
1, 2, -2, 6, -5, 9, 1.02, 45, -69, 77, -12, 2, 8, -2, -4, 59, 7, -3,
];
function arrAbsoluteValues(arr) {
arr = arr.map((s) => Math.abs(s));
}
console.log(arrAbsoluteValues(numbers));
I'm trying to get array that would convert all negative numbers into positive, but I'm getting undefined.
output I expect: [ 1, 2, 2, 6, 5, 9, 1.02, 45, 69, 77, 12, 2, 8, 2, 4, 59, 7, 3, ]
CodePudding user response:
need to add return
in arrAbsoluteValues
function
var numbers = [
1, 2, -2, 6, -5, 9, 1.02, 45, -69, 77, -12, 2, 8, -2, -4, 59, 7, -3,
];
function arrAbsoluteValues(arr) {
return arr.map((s) => Math.abs(s));
}
console.log(arrAbsoluteValues(numbers));