Fun fact about JavaScript: it's a... bit inconsistent. For example, functions like Array.map, Array.reduce, Array.sort don't mutate the array, but Array.unshift does, and returns array's length after the element was added.

  • 5
    Pretty sure Array.sort mutates array. The whole point of unshift is to add an element to array, there's Array.concat if you'd like to create a new array with extra elements. And how would Array.reduce even mutate an array?
  • 1

    Well, you're right! My mistake.
  • 2
    @mishaor you say javascript is inconsistent and use that as an example?
  • 1
    just keep studying, you'll get the hang of it. There's a reason behind some of them making copy and some of them mutating. It might help to make you a chart of which is which til you cam remember
  • 3
    You'll find many worse things about JS than that...
  • 0
    Message to future me: think before you post
  • 1
    @mishaor honest mistake, I don't think I've ever went thru a set of js documentation that had them clearly organized into which did what. On mdn you have to read thru each method individually to find out so your constantly flipping back and forth til you get them memorized.
Add Comment