was.js – Diff between revs 2 and 5
?pathlinks?
Rev 2 | Rev 5 | |||
---|---|---|---|---|
Line 8... | Line 8... | |||
8 | new Array(Math.max(this.length, a.length)), |
8 | new Array(Math.max(this.length, a.length)), |
|
9 | function(e, i) { |
9 | function(e, i) { |
|
10 | var o = {}; |
10 | var o = {}; |
|
11 | o[a[i]] = b[i]; |
11 | o[a[i]] = b[i]; |
|
12 | return o; |
12 | return o; |
|
13 | }); |
13 | }); |
|
14 | }; |
14 | }; |
|
15 | } |
15 | } |
|
16 | $.extend({ |
16 | $.extend({ |
|
17 | product: function(a, b) { |
17 | product: function(a, b) { |
|
18 | return $.map( |
18 | return $.map( |
|
19 | new Array(Math.max(this.length, a.length)), |
19 | new Array(Math.max(this.length, a.length)), |
|
20 | function(e, i) { |
20 | function(e, i) { |
|
21 | var o = {}; |
21 | var o = {}; |
|
22 | o[a[i]] = b[i]; |
22 | o[a[i]] = b[i]; |
|
23 | return o; |
23 | return o; |
|
24 | }); |
24 | }); |
|
25 | } |
25 | } |
|
26 | }); |
26 | }); |
|
Line 27... | Line 27... | |||
27 | |
27 | |
|
28 | /*************************************************************************/ |
28 | /*************************************************************************/ |
|
Line 62... | Line 62... | |||
62 | } |
62 | } |
|
63 | return [a.slice(0, n)] |
63 | return [a.slice(0, n)] |
|
64 | .concat(a.slice(n).chunk(n)); |
64 | .concat(a.slice(n).chunk(n)); |
|
65 | } |
65 | } |
|
66 | }); |
66 | }); |
|
- | 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 | }); |