Ad
  • Custom User Avatar

    Sorry, whrere should I put it? Thx!

  • Custom User Avatar

    absolutely love it :)

  • Custom User Avatar

    var nums is a converted numbers(string) argument to an array by applying .split(), then .map() method returns a new array of 0s ans 1s;
    var sum is the sum of all elements in "nums" array.
    var target is being assigned to 0, or 1, as we know that nums contain ony 0s and 1s, if the sum is greater than 1, it means that majority of numbers were odd, otherwise even.

    return statement is a beauty, because we search for an index of element with value 0, or 1, which is unique in 'nums' array.