]> git.r.bdr.sh - rbdr/dotfiles/blob
900771a6f818a41983f7b45e836ed6f790eb9d6c
[rbdr/dotfiles] /
1 'use strict';
2
3 module.exports = {
4 __generic: function (t, a) {
5 var count = 0, first, last, x, icount = this.length;
6 t.call(this, function (item, index, col) {
7 ++count;
8 if (!first) {
9 first = item;
10 }
11 last = item;
12 x = col;
13 a(index, --icount, "Index");
14 });
15 a(count, this.length, "Iterated");
16 a(first, this[this.length - 1], "First is last");
17 a(last, this[0], "Last is first");
18 a.deep(x, Object(this), "Collection as third argument"); //jslint: skip
19 },
20 "": function (t, a) {
21 var x = {}, y, count;
22 t.call([1], function () { y = this; }, x);
23 a(y, x, "Scope");
24 y = 0;
25 t.call([3, 4, 4], function (a, i) { y += i; });
26 a(y, 3, "Indexes");
27
28 x = [1, 3];
29 x[5] = 'x';
30 y = 0;
31 count = 0;
32 a(t.call(x, function (a, i) { ++count; y += i; }), false, "Return");
33 a(y, 6, "Misssing Indexes");
34 a(count, 3, "Misssing Indexes, count");
35
36 count = 0;
37 a(t.call([-2, -3, -4, 2, -5], function (item) {
38 ++count;
39 return item > 0;
40 }), true, "Return");
41 a(count, 2, "Break after true is returned");
42 }
43 };