1. 4
  1.  

  2. 11

    I recommend Ramda for most of these cases: http://ramdajs.com/

    1. 6

      This array_unique would work only for things that are unique according to .toString, so {a: 'val'} and {b: 'val'} would be considered as duplicates. example on jsbin

      You can fix it by using Map from ES6, though.

      1. 2

        Essential functions in JavaScript in vanilla form (inspired by PHP)

        I got you, fam: https://github.com/amitmerchant1990/essential-vanilla-javascript-functions/pull/2

        1. 1

          Yup. The very first function listed, and it doesn’t work. Pass :D

          Edit: In fact, no need for Map, just use ret_arr.indexOf()

        2. 4

          array_map() - Sends each value of an array to a user-made function, which returns new values

          Uh, this function isn’t missing from vanilla javascript, what am I missing here?

          1. 2

            I noticed that as well. A lot of this functionality already exists. For example they implemented array_split() when the Array object has a splice() method already.

            1. 2

              Also array_merge is a side-effecty Array.prototype.concat

            2. 3

              The JavaScript stdlib is weird and shitty because of how imperative it is for a functional language, but I’m not sure if I’d learn from PHP’s stdlib…

              1. 2

                I like the novelty of this, but a lot of the functionality written here is already defined in the Array object for the JavaScript language.

                1. 2

                  This seems like a good programming exercise; it would be interesting to analyze the complexity of some of the algorithms implemented here in JS and compare it to PHP’s own implementation.

                  For something a bit more tested, a while ago there was a project called phpjs which now became Locutus; it aimed to implement a solid chunk of PHP’s standard library in JavaScript. I remember using their implementation of PHP’s strtotime function a few times with solid success.