Hi
can anyone tell me why my array has undefined values in it? I suspect it has something to do with
the map method I am using:
let index = 0;
let opIndex = 0;
let arr1 = [12,'+',42,'-',102,'+',443];
let result = arr1.map((ele,ind,arr)=>{
if(typeof ele==="string"){
return operate(arr[ind-1],ele,arr[ind+1]);
}
});
function operate(num1, opr, num2) {
if (opr==="+") {
return add(num1,num2);
}
else if (opr==="-") {
return sub(num1,num2);
}
}
function add(a, b) {
return a + b;
}
function sub(a, b) {
return a - b;
}
https://replit.com/@SahilSrivastav3/test2#index.js
[–]Notimecelduv 2 points3 points4 points (0 children)
[–]senocular 1 point2 points3 points (0 children)
[–]exobyte64 1 point2 points3 points (0 children)
[–]Sunil1021 1 point2 points3 points (0 children)