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
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.
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.
I recommend Ramda for most of these cases: http://ramdajs.com/
This
array_uniquewould work only for things that are unique according to.toString, so{a: 'val'}and{b: 'val'}would be considered as duplicates. example on jsbinYou can fix it by using Map from ES6, though.
I got you, fam: https://github.com/amitmerchant1990/essential-vanilla-javascript-functions/pull/2
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()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?
I noticed that as well. A lot of this functionality already exists. For example they implemented
array_split()when the Array object has asplice()method already.Also array_merge is a side-effecty Array.prototype.concat
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…
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.
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
phpjswhich now became Locutus; it aimed to implement a solid chunk of PHP’s standard library in JavaScript. I remember using their implementation of PHP’sstrtotimefunction a few times with solid success.