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.

  • Default User Avatar

    uses no variables and it's the only solution that would save time making only 1 comparision and returning. if it's lucky it saves 66% time.
    when you write it like (a+b<=c & a+c blabla) it will lose time doing all 3 comparisions ... or am I wrong?