2
mishaor
4y

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.

Comments
  • 3
    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
    @hitko

    Well, you're right! My mistake.
  • 2
    @mishaor you say javascript is inconsistent and use that as an example?
  • 2
    You'll find many worse things about JS than that...
  • 0
    Message to future me: think before you post
Add Comment