was.js – Blame information for rev 5
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
2 | office | 1 | /*************************************************************************/ |
2 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
3 | /*************************************************************************/ |
||
4 | if (!Array.prototype.product) { |
||
5 | Array.prototype.product = function(b) { |
||
6 | var a = this; |
||
7 | return $.map( |
||
8 | new Array(Math.max(this.length, a.length)), |
||
9 | function(e, i) { |
||
10 | var o = {}; |
||
11 | o[a[i]] = b[i]; |
||
12 | return o; |
||
5 | office | 13 | }); |
2 | office | 14 | }; |
15 | } |
||
16 | $.extend({ |
||
17 | product: function(a, b) { |
||
18 | return $.map( |
||
19 | new Array(Math.max(this.length, a.length)), |
||
20 | function(e, i) { |
||
21 | var o = {}; |
||
22 | o[a[i]] = b[i]; |
||
23 | return o; |
||
5 | office | 24 | }); |
2 | office | 25 | } |
26 | }); |
||
27 | |||
28 | /*************************************************************************/ |
||
29 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
30 | /*************************************************************************/ |
||
31 | if (!Array.prototype.stride) { |
||
32 | Array.prototype.stride = function(s) { |
||
33 | return this.filter(function(e, i) { |
||
34 | return i % s === 0; |
||
35 | }); |
||
36 | }; |
||
37 | } |
||
38 | $.extend({ |
||
39 | stride: function(a, s) { |
||
40 | return a.filter(function(e, i) { |
||
41 | return i % s === 0; |
||
42 | }); |
||
43 | } |
||
44 | }); |
||
45 | |||
46 | /*************************************************************************/ |
||
47 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
48 | /*************************************************************************/ |
||
49 | if (!Array.prototype.chunk) { |
||
50 | Array.prototype.chunk = function(n) { |
||
51 | if (!this.length) { |
||
52 | return []; |
||
53 | } |
||
54 | return [this.slice(0, n)] |
||
55 | .concat(this.slice(n).chunk(n)); |
||
56 | }; |
||
57 | } |
||
58 | $.extend({ |
||
59 | chunk: function(a, n) { |
||
60 | if (!a.length) { |
||
61 | return []; |
||
62 | } |
||
63 | return [a.slice(0, n)] |
||
64 | .concat(a.slice(n).chunk(n)); |
||
65 | } |
||
66 | }); |
||
5 | office | 67 | |
68 | /*************************************************************************/ |
||
69 | /* Copyright (C) 2017 Wizardry and Steamworks - License: GNU GPLv3 */ |
||
70 | /*************************************************************************/ |
||
71 | /*stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript*/ |
||
72 | /*************************************************************************/ |
||
73 | if (!Array.prototype.equals) { |
||
74 | // attach the .equals method to Array's prototype to call it on any array |
||
75 | Array.prototype.equals = function(a) { |
||
76 | // if the other array is a falsy value, return |
||
77 | if (!a) { |
||
78 | return false; |
||
79 | } |
||
80 | |||
81 | // compare lengths - can save a lot of time |
||
82 | if (this.length !== a.length) { |
||
83 | return false; |
||
84 | } |
||
85 | |||
86 | for (var i = 0, l = this.length; i < l; i++) { |
||
87 | // Check if we have nested arrays |
||
88 | if (this[i] instanceof Array && a[i] instanceof Array) { |
||
89 | // recurse into the nested arrays |
||
90 | if (!this[i].equals(a[i])) { |
||
91 | return false; |
||
92 | } |
||
93 | } else if (this[i] !== a[i]) { |
||
94 | // Warning - two different object instances will never be equal: {x:20} != {x:20} |
||
95 | return false; |
||
96 | } |
||
97 | } |
||
98 | return true; |
||
99 | }; |
||
100 | } |
||
101 | |||
102 | $.extend({ |
||
103 | equals: function(a) { |
||
104 | // if the other array is a falsy value, return |
||
105 | if (!a) { |
||
106 | return false; |
||
107 | } |
||
108 | |||
109 | // compare lengths - can save a lot of time |
||
110 | if (this.length !== a.length) { |
||
111 | return false; |
||
112 | } |
||
113 | |||
114 | for (var i = 0, l = this.length; i < l; i++) { |
||
115 | // Check if we have nested arrays |
||
116 | if (this[i] instanceof Array && a[i] instanceof Array) { |
||
117 | // recurse into the nested arrays |
||
118 | if (!this[i].equals(a[i])) { |
||
119 | return false; |
||
120 | } |
||
121 | } else if (this[i] !== a[i]) { |
||
122 | // Warning - two different object instances will never be equal: {x:20} != {x:20} |
||
123 | return false; |
||
124 | } |
||
125 | } |
||
126 | return true; |
||
127 | } |
||
128 | }); |