In this node.js file I am working on a coding solution where i manipulate every third or fifth element in the array without using loops. So using the map method and using index as one of the paramenters should let me achieve this. If i use this code in a regular javascript template on replit it works fine. Also the code works fine on codewars and vscode but it doesnt work in my node.js collection for whatever reason it wont access the index in the custom map functions. Why is that? Did i do something wrong or is it just a weird replit thing?
Repl link:
https://replit.com/@spudsnbuds/CW#Code-Wars/Operations%20with%20sequence.js
var calc = function(a) {
let square = a.map(x => {
if (x > 0){
return x * x
}else {
return x
}
})
let copy = [...square]
let third = copy.map((x,i) =>{
if ((i + 1) % 3 == 0){
return x * 3
}else {
return x
}
}
)
let fifth = third.map((x,i) => {
if ((i + 1) % 5 == 0){
return x * -1
}else {
return x
}
})
return fifth.reduce((curr,acc) => {
return curr + acc
})
}
console.log(calc([ 0, 2, 1, -6, -3, 3 ]))
The answer should be 31. Not 5 like when I run this code in my file