Как сказал @uminder
, строка var abc = orange
в строке abc
ссылается на массив orange
. Так что обе ссылки одинаковы.
Вместо этого вы можете сделать var abc = [...orange]
.
function countApplesAndOranges(s, t, a, b, apples, oranges) {
var abc = [...oranges];
abc.forEach(function(item, index, arr) {
arr[index] = item + t
});
console.log(abc)
console.log(oranges)
}
ИЛИ ,
function countApplesAndOranges(s, t, a, b, apples, oranges) {
var abc = [];
oranges.forEach(function(item, index) {
abc[index] = item + t
});
console.log(abc)
console.log(oranges)
}