In addition, here's Erlang's one, which has rich lists library -- http://www.erlang.org/doc/man/lists.html Some/most methods are already implemented in JS of course (though, by different names), but we can take missing, but needed (and thus implemented in many JS libs) methods.

Dmitry.

On 11.07.2011 0:46, Dmitry A. Soshnikov wrote:
Here I put some extensions for arrays standard library (separated from this thread: https://mail.mozilla.org/pipermail/es-discuss/2011-July/015856.html where Array.of and Array.from were considered).

We can consider also the following (as a first step):

*- Array.prototype.remove(value, all)*

[1, 2, 3, 2].remove(2); // [1, 3, 2]
[1, 2, 3, 2].remove(2, true); // [1, 3]

(seems this function is required more than Array.of, because at least I saw it implemented in all frameworks and used it myself).

*- Array.prototype.subtract(array)*

[1, 2, 3, 4].subtract([2, 4]); // [1, 3]

*- Array.seq(from, to)* // or Array.range(from, to)

Array.seq(1, 5); // [1, 2, 3, 4, 5]

*- Array.build(n, fn)*

Array.build(5, function(index) index + 1); // [1, 2, 3, 4, 5]

*- Array.min(array), Array.max(array)* (can be implemented with Math.max/min and apply though)

Array.min = (array) -> Math.min.apply(Math, array)

*- Array.prototype.split(n)*

["a", "b", "c", "d", "e"].split(3) // [["a", "b", "c"], ["d", "e", "f"]]

Perhaps even to build objects from lists of keys and values (this function is usually called as `zip`):

*- Object.fromArrays(["a", "b", "c"], [1, 2, 3]);* // {a: 1, b: 2, c: 3}

*- Array.prototype.unique*

[1, 3, 2, 5, 5, 3].unique(); // [1, 3, 2, 5]

Thus, all names of methods can be discussed.

Dmitry.

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to