Why you do this in dedicated copy, not original array itself?

@mtf Really its an advanced one to share this here man…
Try to understand why you do this in dedicated copy , not original array itself … If you donot understand, its okay … Don’t stress more on it as if now guys…

// PRINGTING WITHOUT ALTERING ORIGNINAL ARRAY

a = "abcd".split("")
console.log(a) //=> [ 'a', 'b', 'c', 'd' ]

log = x => {
    console.log(x) //=> just prints the value
}

a.forEach(log) //=> a|b|c|d 
console.log(a) //=> [ 'a', 'b', 'c', 'd' ]


// PRINGTING WITH ALTERING ORIGNINAL ARRAY

// example 1

a = "abcd".split("")
console.log(a) //=> [ 'a', 'b', 'c', 'd' ]

log = () => {
  console.log(a.shift())  // remove first element
}

console.log(a.slice()) //=> [ 'a', 'b', 'c', 'd' ]
console.log(a)  //=> [ 'a', 'b', 'c', 'd' ]

//We do updation of original array, length varies dynamically here
//so it will go upto half or half+1  length only
a.forEach(log) //=> a | b
console.log(a) //=> ['c','d']

a.slice().forEach(log) //=> c | d
console.log(a) //=> [ ]


// example 2

a = "abcdefg".split("")
console.log(a) //=> [ 'a', 'b', 'c', 'd', 'e', 'f','g' ]

log = () => {
  console.log(a.pop()) // remove last element
}

a.forEach(log) //=> g | f | e | d
console.log(a) //=> [ 'a', 'b', 'c' ]
a.forEach(log) //=> c | b
console.log(a) //=> ['a']

a.slice().forEach(log) //=> a
console.log(a) //=> [ ]

// PRINGTING WITHOUT ALTERING ORIGNINAL ARRAY a = "abcd".split("") console.log(a) //=> [ 'a', 'b', 'c', 'd' ] log = x => { console.log(x) } a.forEach(log) //=> a|b|c|d console.log(a) //=> [ 'a', 'b', 'c', 'd' ] // PRINGTING WITH ALTERING ORIGNINAL ARRAY // example 1 a = "abcd".split("") console.log(a) //=> [ 'a', 'b', 'c', 'd' ] log = () => { console.log(a.shift()) // remove first element } console.log(a.slice()) //=> [ 'a', 'b', 'c', 'd' ] console.log(a) //=> [ 'a', 'b', 'c', 'd' ] //We do updation of original array, length varies dynamically here //so it will go upto half or half+1 length only a.forEach(log) //=> a | b console.log(a) //=> ['c','d'] a.slice().forEach(log) //=> c | d console.log(a) //=> [ ] // example 2 a = "abcdefg".split("") console.log(a) //=> [ 'a', 'b', 'c', 'd', 'e', 'f','g' ] log = () => { console.log(a.pop()) // remove last element } a.forEach(log) //=> g | f | e | d console.log(a) //=> [ 'a', 'b', 'c' ] a.forEach(log) //=> c | b console.log(a) //=> ['a'] a.slice().forEach(log) //=> a console.log(a) //=> [ ]

It’s just a simplified approach to creating an array from a string with less typing.