I'm trying to eliminate the minimum and maximum values from the below array and create 2 new arrays without the maximum and minimum values
array = [4, 6, 7, 8, 9]
const indOmin = 0,
indOm = 5
minArr = arr
maxArr = arr
minArr.forEach(cur => {
if (arr.indexOf(cur) === indOmin) {
minArr.splice(indOmin, 1)
}
})
maxArr.forEach(cur => {
if (arr.indexOf(cur) === indOm) {
maxArr.splice(indOm, 1)
}
})
When I use...
console.log(minArr)
console.log(maxArr)
...then in both cases it returns [6, 7, 8, 9]
.
But instead of...
minArr = arr
maxArr = arr
...if I use...
minArr = arr.map(cur => cur = cur)
maxArr = arr.map(cur => cur = cur)
... then the arrays return expected values.
[6, 7, 8, 9]
[4, 6, 7, 8]
Please help me understand why it doesn't work when I explicitly use the =
operator (minArr = arr
).