Ad
  • Default User Avatar
    1. Yes, slice is retruning just [2,3]. But the thing is the reduce methode dosen't work on that array. In this example the reduce method uses the original arr array. The return value from slice would be the fourth argument in the reduce methode (acc,curr,index,array). Because array has only two elements reduce is called only two times. Thats why it works.

    2. From 1) follows that arr.length is 4 for you example and index max value is 1 because it's the index auf the array that was returned from the slice method. So it can't be NaN.