@blazedpath/commons 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,446 +1,448 @@
1
1
  module.exports = {
2
- errorUndefinedArgument: function( argName ) {
3
- const err = new Error();
4
- err.code = 'UndefinedArgument';
5
- err.data = { argName: argName };
6
- return err;
7
- },
8
- compare: function( value1, value2 ) { // TODO: Sort require for objects
9
- if( value1 === null && value2 === null ) return 0;
10
- if( value1 === null && value2 !== null ) return -1;
11
- if( value1 !== null && value2 === null ) return 1;
12
-
13
- const value1Type = toString.call( value1 );
14
- const value2Type = toString.call( value2 );
15
- let value1ToCompare = null;
16
- let value2ToCompare = null;
17
- if ((value1Type === '[object String]' && value2Type === '[object String]') ||
18
- (value1Type === '[object Number]' && value2Type === '[object Number]')) {
19
- value1ToCompare = value1;
20
- value2ToCompare = value2;
21
- }
22
- else if( value1Type === '[object Boolean]' && value2Type === '[object Boolean]' ) {
23
- value1ToCompare = value1 ? 1 : 0;
24
- value2ToCompare = value2 ? 1 : 0;
25
- }
26
- else if( value1Type === '[object Date]' && value2Type === '[object Date]' ) {
27
- value1ToCompare = value1.getTime();
28
- value2ToCompare = value2.getTime();
29
- }
30
- else if( value1Type === '[object Object]' && value2Type === '[object Object]' ) {
31
- value1ToCompare = JSON.stringify( value1 );
32
- value2ToCompare = JSON.stringify( value2 );
33
- }
34
- else if( value1Type === '[object Array]' && value2Type === '[object Array]' ) {
35
- let result = this.compare( value1.length, value2.length );
36
- if( result !== 0 )
37
- return result;
38
- for( let i = 0; i < value1.length; ++i ) {
39
- const item1 = value1[ i ];
40
- const item2 = value2[ i ];
41
- result = this.compare( item1, item2 );
42
- if( result !== 0 )
2
+ Dual: {
3
+ errorUndefinedArgument: function (argName) {
4
+ const err = new Error();
5
+ err.code = 'UndefinedArgument';
6
+ err.data = { argName: argName };
7
+ return err;
8
+ },
9
+ compare: function (value1, value2) { // TODO: Sort require for objects
10
+ if (value1 === null && value2 === null) return 0;
11
+ if (value1 === null && value2 !== null) return -1;
12
+ if (value1 !== null && value2 === null) return 1;
13
+
14
+ const value1Type = toString.call(value1);
15
+ const value2Type = toString.call(value2);
16
+ let value1ToCompare = null;
17
+ let value2ToCompare = null;
18
+ if ((value1Type === '[object String]' && value2Type === '[object String]') ||
19
+ (value1Type === '[object Number]' && value2Type === '[object Number]')) {
20
+ value1ToCompare = value1;
21
+ value2ToCompare = value2;
22
+ }
23
+ else if (value1Type === '[object Boolean]' && value2Type === '[object Boolean]') {
24
+ value1ToCompare = value1 ? 1 : 0;
25
+ value2ToCompare = value2 ? 1 : 0;
26
+ }
27
+ else if (value1Type === '[object Date]' && value2Type === '[object Date]') {
28
+ value1ToCompare = value1.getTime();
29
+ value2ToCompare = value2.getTime();
30
+ }
31
+ else if (value1Type === '[object Object]' && value2Type === '[object Object]') {
32
+ value1ToCompare = JSON.stringify(value1);
33
+ value2ToCompare = JSON.stringify(value2);
34
+ }
35
+ else if (value1Type === '[object Array]' && value2Type === '[object Array]') {
36
+ let result = this.compare(value1.length, value2.length);
37
+ if (result !== 0)
43
38
  return result;
39
+ for (let i = 0; i < value1.length; ++i) {
40
+ const item1 = value1[i];
41
+ const item2 = value2[i];
42
+ result = this.compare(item1, item2);
43
+ if (result !== 0)
44
+ return result;
45
+ }
46
+ return 0;
44
47
  }
45
- return 0;
46
- }
47
- else {
48
- const getValueToCompare = ( valueType, value ) => {
49
- switch( valueType ) {
50
- case '[object String]' : return value
51
- case '[object Number]' : return value.toString()
52
- case '[object Boolean]' : return value ? '1' : '0'
53
- case '[object Date]' : return value.toJSON()
54
- default : return value.toString()
48
+ else {
49
+ const getValueToCompare = (valueType, value) => {
50
+ switch (valueType) {
51
+ case '[object String]': return value
52
+ case '[object Number]': return value.toString()
53
+ case '[object Boolean]': return value ? '1' : '0'
54
+ case '[object Date]': return value.toJSON()
55
+ default: return value.toString()
56
+ }
57
+
55
58
  }
56
59
 
60
+ value1ToCompare = getValueToCompare(value1Type, value1)
61
+ value2ToCompare = getValueToCompare(value2Type, value2)
57
62
  }
58
63
 
59
- value1ToCompare = getValueToCompare( value1Type, value1 )
60
- value2ToCompare = getValueToCompare( value2Type, value2 )
61
- }
62
-
63
- if( value1ToCompare === value2ToCompare ) return 0;
64
- else if( value1ToCompare < value2ToCompare ) return -1;
65
- else if( value1ToCompare > value2ToCompare ) return 1;
66
- else return null;
64
+ if (value1ToCompare === value2ToCompare) return 0;
65
+ else if (value1ToCompare < value2ToCompare) return -1;
66
+ else if (value1ToCompare > value2ToCompare) return 1;
67
+ else return null;
67
68
 
68
- },
69
- all: function( list, fnCondition ) {
70
- if( list === null ) return false;
69
+ },
70
+ all: function (list, fnCondition) {
71
+ if (list === null) return false;
71
72
 
72
- for( let i = 0; i < list.length; ++i ) {
73
- const item = list[ i ];
74
- if( !(fnCondition( item )) )
75
- return false;
76
- }
77
- return true;
78
- },
79
- any: function( list, fnCondition ) {
80
- if( list === null ) return false;
81
-
82
- for( let i = 0; i < list.length; ++i ) {
83
- const item = list[ i ];
84
- if( fnCondition( item ) )
85
- return true;
86
- }
87
- return false;
88
- },
89
- avg: function( list, fnSelection ) {
90
- if( list === null ) return null;
91
-
92
- let totalSum = 0;
93
- let totalCount = 0;
94
- if( fnSelection ) {
95
- for( let i = 0; i < list.length; ++i ) {
96
- const item = list[ i ];
97
- const value = fnSelection( item );
98
- if( value !== null ) {
99
- totalSum += value;
100
- totalCount++;
73
+ for (let i = 0; i < list.length; ++i) {
74
+ const item = list[i];
75
+ if (!(fnCondition(item)))
76
+ return false;
77
+ }
78
+ return true;
79
+ },
80
+ any: function (list, fnCondition) {
81
+ if (list === null) return false;
82
+
83
+ for (let i = 0; i < list.length; ++i) {
84
+ const item = list[i];
85
+ if (fnCondition(item))
86
+ return true;
87
+ }
88
+ return false;
89
+ },
90
+ avg: function (list, fnSelection) {
91
+ if (list === null) return null;
92
+
93
+ let totalSum = 0;
94
+ let totalCount = 0;
95
+ if (fnSelection) {
96
+ for (let i = 0; i < list.length; ++i) {
97
+ const item = list[i];
98
+ const value = fnSelection(item);
99
+ if (value !== null) {
100
+ totalSum += value;
101
+ totalCount++;
102
+ }
101
103
  }
102
104
  }
103
- }
104
- else {
105
- for( let i = 0; i < list.length; ++i ) {
106
- const value = list[ i ];
107
- if( value !== null ) {
108
- totalSum += value;
109
- totalCount++;
105
+ else {
106
+ for (let i = 0; i < list.length; ++i) {
107
+ const value = list[i];
108
+ if (value !== null) {
109
+ totalSum += value;
110
+ totalCount++;
111
+ }
110
112
  }
111
113
  }
112
- }
113
- return totalSum / totalCount;
114
- },
115
- concatList: function() {
116
- if( arguments.length === 0 ) return null
117
- if( arguments.length === 1 && arguments[ 0 ] === null ) return null
118
- return Array.from( arguments ).filter( list => list !== null ).flat()
119
- },
120
- count: function( list ) {
121
- if( list === null ) return null;
122
- return list.length;
123
- },
124
- distinct: function( list, fnSelection ) {
125
- if( list === null ) return null;
126
-
127
- const resultArray = [];
128
- if( fnSelection ) {
129
- const keys = [];
130
- for( let i = 0; i < list.length; ++i ) {
131
- const item = list[ i ];
132
- const key = fnSelection( item );
133
- if( keys.indexOf( key ) === -1 ) {
134
- keys.push( key );
135
- resultArray.push( item );
114
+ return totalSum / totalCount;
115
+ },
116
+ concatList: function () {
117
+ if (arguments.length === 0) return null
118
+ if (arguments.length === 1 && arguments[0] === null) return null
119
+ return Array.from(arguments).filter(list => list !== null).flat()
120
+ },
121
+ count: function (list) {
122
+ if (list === null) return null;
123
+ return list.length;
124
+ },
125
+ distinct: function (list, fnSelection) {
126
+ if (list === null) return null;
127
+
128
+ const resultArray = [];
129
+ if (fnSelection) {
130
+ const keys = [];
131
+ for (let i = 0; i < list.length; ++i) {
132
+ const item = list[i];
133
+ const key = fnSelection(item);
134
+ if (keys.indexOf(key) === -1) {
135
+ keys.push(key);
136
+ resultArray.push(item);
137
+ }
136
138
  }
137
139
  }
138
- }
139
- else {
140
- for( let i = 0; i < list.length; ++i ) {
141
- const item = list[ i ];
142
- if( resultArray.indexOf( item ) === -1 )
143
- resultArray.push( item );
140
+ else {
141
+ for (let i = 0; i < list.length; ++i) {
142
+ const item = list[i];
143
+ if (resultArray.indexOf(item) === -1)
144
+ resultArray.push(item);
145
+ }
144
146
  }
145
- }
146
- return resultArray;
147
- },
148
- elementAt: function( list, index ) {
149
- if( list === null ) return null
150
-
151
- const result = list[ index ]
152
- return result === undefined ? null : result
153
- },
154
- getSelections: function( list, fnSelection ) {
155
- if( !fnSelection ) return list
156
-
157
- const selections = new Array( list.length )
158
- for( let i = 0; i < list.length; ++i ) {
159
- selections[ i ] = fnSelection( list[ i ] )
160
- }
161
- return selections
162
- },
163
- except: function( listA, listB, fnSelection ) {
164
- if( listA === null ) return null
165
- if( listB === null ) return listA.slice()
166
-
167
- const selectionsA = this.getSelections( listA, fnSelection )
168
- const selectionsB = this.getSelections( listB, fnSelection )
169
-
170
- const resultArray = [];
171
- for( let i = 0; i < listA.length; ++i ) {
172
- let except = false
173
- for( let j = 0; j < listB.length; ++j ) {
174
- if( this.compare( selectionsA[ i ], selectionsB[ j ] ) === 0 ) {
175
- except = true
176
- break
147
+ return resultArray;
148
+ },
149
+ elementAt: function (list, index) {
150
+ if (list === null) return null
151
+
152
+ const result = list[index]
153
+ return result === undefined ? null : result
154
+ },
155
+ getSelections: function (list, fnSelection) {
156
+ if (!fnSelection) return list
157
+
158
+ const selections = new Array(list.length)
159
+ for (let i = 0; i < list.length; ++i) {
160
+ selections[i] = fnSelection(list[i])
161
+ }
162
+ return selections
163
+ },
164
+ except: function (listA, listB, fnSelection) {
165
+ if (listA === null) return null
166
+ if (listB === null) return listA.slice()
167
+
168
+ const selectionsA = this.getSelections(listA, fnSelection)
169
+ const selectionsB = this.getSelections(listB, fnSelection)
170
+
171
+ const resultArray = [];
172
+ for (let i = 0; i < listA.length; ++i) {
173
+ let except = false
174
+ for (let j = 0; j < listB.length; ++j) {
175
+ if (this.compare(selectionsA[i], selectionsB[j]) === 0) {
176
+ except = true
177
+ break
178
+ }
177
179
  }
180
+ if (!except) resultArray.push(listA[i])
181
+ }
182
+ return resultArray;
183
+ },
184
+ findAll: function (list, fnCondition) {
185
+ if (list === null) return null;
186
+
187
+ const resultArray = [];
188
+ for (let i = 0; i < list.length; ++i) {
189
+ const item = list[i];
190
+ if (fnCondition(item))
191
+ resultArray.push(item);
192
+ }
193
+ return resultArray;
194
+ },
195
+ findFirstInternal: function (list, fnCondition) {
196
+ if (list === null) return null
197
+
198
+ for (let i = 0; i < list.length; ++i) {
199
+ const item = list[i]
200
+ if (fnCondition(item))
201
+ return { item, index: i }
178
202
  }
179
- if( !except ) resultArray.push( listA[ i ] )
180
- }
181
- return resultArray;
182
- },
183
- findAll: function( list, fnCondition ) {
184
- if( list === null ) return null;
185
-
186
- const resultArray = [];
187
- for( let i = 0; i < list.length; ++i ) {
188
- const item = list[ i ];
189
- if( fnCondition( item ) )
190
- resultArray.push( item );
191
- }
192
- return resultArray;
193
- },
194
- findFirstInternal: function( list, fnCondition ) {
195
- if( list === null ) return null
196
-
197
- for( let i = 0; i < list.length; ++i ) {
198
- const item = list[ i ]
199
- if( fnCondition( item ) )
200
- return { item, index: i }
201
- }
202
203
 
203
- return { item: null, index: -1 }
204
- },
205
- findFirst: function( list, fnCondition ) {
206
- const result = this.findFirstInternal( list, fnCondition )
207
- return result === null ? null : result.item
208
- },
209
- findIndex: function( list, fnCondition ) {
210
- const result = this.findFirstInternal( list, fnCondition )
211
- return result === null ? null : result.index
212
- },
213
- findLastInternal: function( list, fnCondition ) {
214
- if( list === null ) return null
215
-
216
- for( let i = ( list.length - 1 ); i > -1; i-- ) {
217
- const item = list[ i ]
218
- if( fnCondition( item ) )
219
- return { item, index: i }
220
- }
221
- return { item: null, index: -1 }
222
- },
223
- findLast: function( list, fnCondition ) {
224
- const result = this.findLastInternal( list, fnCondition )
225
- return result === null ? null : result.item
226
- },
227
- findLastIndex: function( list, fnCondition ) {
228
- const result = this.findLastInternal( list, fnCondition )
229
- return result === null ? null : result.index
230
- },
231
- first: function( list ) {
232
- if( list === null ) return null;
233
- return list.length > 0 ? list[ 0 ] : null;
234
- },
235
- flat: function( list, depth ) {
236
- if( list === null ) return null
237
- return list.flat( depth )
238
- },
239
- includes: function( list, searchElement, fromIndex ) {
240
- if( list === null ) return false
241
- return list.includes( searchElement, fromIndex )
242
- },
243
- insertAt: function( list, index, elements ) {
244
- if( list === null ) return null
245
- if( elements === null ) return list.slice()
246
- const copiedList = list.slice()
247
- copiedList.splice( index, 0, ...elements )
248
- return copiedList
249
- },
250
- intersect: function( listA, listB, fnSelection ) {
251
- if( listA === null ) return null;
252
- if( listB === null ) return null;
253
-
254
- const selectionsA = this.getSelections( listA, fnSelection )
255
- const selectionsB = this.getSelections( listB, fnSelection )
256
-
257
- const resultArray = [];
258
- for( let i = 0; i < listA.length; ++i ) {
259
- let include = false;
260
- for( let j = 0; j < listB.length; j++ ) {
261
- if( this.compare( selectionsA[ i ], selectionsB[ j ] ) === 0 )
262
- include = true;
204
+ return { item: null, index: -1 }
205
+ },
206
+ findFirst: function (list, fnCondition) {
207
+ const result = this.findFirstInternal(list, fnCondition)
208
+ return result === null ? null : result.item
209
+ },
210
+ findIndex: function (list, fnCondition) {
211
+ const result = this.findFirstInternal(list, fnCondition)
212
+ return result === null ? null : result.index
213
+ },
214
+ findLastInternal: function (list, fnCondition) {
215
+ if (list === null) return null
216
+
217
+ for (let i = (list.length - 1); i > -1; i--) {
218
+ const item = list[i]
219
+ if (fnCondition(item))
220
+ return { item, index: i }
263
221
  }
264
- if( include )
265
- resultArray.push( listA[ i ] );
266
- }
267
- return resultArray;
268
- },
269
- last: function( list ) {
270
- if( list === null ) return null;
271
- return list.length > 0 ? list[ list.length - 1 ] : null;
272
- },
273
- max: function( list, fnSelection ) {
274
- if( list === null ) return null;
275
-
276
- let max = null;
277
- if( fnSelection ) {
278
- for( let i = 0; i < list.length; ++i ) {
279
- const item = list[ i ];
280
- const value = fnSelection( item );
281
- if( max === null || this.compare( value, max ) > 0 )
282
- max = value;
222
+ return { item: null, index: -1 }
223
+ },
224
+ findLast: function (list, fnCondition) {
225
+ const result = this.findLastInternal(list, fnCondition)
226
+ return result === null ? null : result.item
227
+ },
228
+ findLastIndex: function (list, fnCondition) {
229
+ const result = this.findLastInternal(list, fnCondition)
230
+ return result === null ? null : result.index
231
+ },
232
+ first: function (list) {
233
+ if (list === null) return null;
234
+ return list.length > 0 ? list[0] : null;
235
+ },
236
+ flat: function (list, depth) {
237
+ if (list === null) return null
238
+ return list.flat(depth)
239
+ },
240
+ includes: function (list, searchElement, fromIndex) {
241
+ if (list === null) return false
242
+ return list.includes(searchElement, fromIndex)
243
+ },
244
+ insertAt: function (list, index, elements) {
245
+ if (list === null) return null
246
+ if (elements === null) return list.slice()
247
+ const copiedList = list.slice()
248
+ copiedList.splice(index, 0, ...elements)
249
+ return copiedList
250
+ },
251
+ intersect: function (listA, listB, fnSelection) {
252
+ if (listA === null) return null;
253
+ if (listB === null) return null;
254
+
255
+ const selectionsA = this.getSelections(listA, fnSelection)
256
+ const selectionsB = this.getSelections(listB, fnSelection)
257
+
258
+ const resultArray = [];
259
+ for (let i = 0; i < listA.length; ++i) {
260
+ let include = false;
261
+ for (let j = 0; j < listB.length; j++) {
262
+ if (this.compare(selectionsA[i], selectionsB[j]) === 0)
263
+ include = true;
264
+ }
265
+ if (include)
266
+ resultArray.push(listA[i]);
283
267
  }
284
- }
285
- else {
286
- for( let i = 0; i < list.length; ++i ) {
287
- const value = list[ i ];
288
- if( max === null || this.compare( value, max ) > 0 )
289
- max = value;
268
+ return resultArray;
269
+ },
270
+ last: function (list) {
271
+ if (list === null) return null;
272
+ return list.length > 0 ? list[list.length - 1] : null;
273
+ },
274
+ max: function (list, fnSelection) {
275
+ if (list === null) return null;
276
+
277
+ let max = null;
278
+ if (fnSelection) {
279
+ for (let i = 0; i < list.length; ++i) {
280
+ const item = list[i];
281
+ const value = fnSelection(item);
282
+ if (max === null || this.compare(value, max) > 0)
283
+ max = value;
284
+ }
290
285
  }
291
- }
292
- return max;
293
- },
294
- min: function( list, fnSelection ) {
295
- if( list === null ) return null;
296
-
297
- let min = null;
298
- if( fnSelection ) {
299
- for( let i = 0; i < list.length; ++i ) {
300
- const item = list[ i ];
301
- const value = fnSelection( item );
302
- if( min === null || this.compare( value, min ) < 0 )
303
- min = value;
286
+ else {
287
+ for (let i = 0; i < list.length; ++i) {
288
+ const value = list[i];
289
+ if (max === null || this.compare(value, max) > 0)
290
+ max = value;
291
+ }
304
292
  }
305
- }
306
- else {
307
- for( let i = 0; i < list.length; ++i ) {
308
- const value = list[ i ];
309
- if( min === null || this.compare( value, min ) < 0 )
310
- min = value;
293
+ return max;
294
+ },
295
+ min: function (list, fnSelection) {
296
+ if (list === null) return null;
297
+
298
+ let min = null;
299
+ if (fnSelection) {
300
+ for (let i = 0; i < list.length; ++i) {
301
+ const item = list[i];
302
+ const value = fnSelection(item);
303
+ if (min === null || this.compare(value, min) < 0)
304
+ min = value;
305
+ }
311
306
  }
312
- }
313
- return min;
314
- },
315
- removeAt: function( list, index, deleteCount ) {
316
- if( list === null ) return null
317
- const copiedList = list.slice()
318
- copiedList.splice( index, deleteCount )
319
- return copiedList
320
- },
321
- reverse: function( list ) {
322
- if( list === null ) return null
323
- return list.slice().reverse()
324
- },
325
- skip: function( list, count ) {
326
- if( list === null ) return null
327
- return list.slice( count )
328
- },
329
- skipWhile: function( list, fnCondition ) {
330
- if( list === null ) return null
331
-
332
- for( let i = 0; i < list.length; ++i ) {
333
- if( !fnCondition( list[ i ] ) ) {
334
- return list.slice( i )
307
+ else {
308
+ for (let i = 0; i < list.length; ++i) {
309
+ const value = list[i];
310
+ if (min === null || this.compare(value, min) < 0)
311
+ min = value;
312
+ }
335
313
  }
336
- }
337
- return []
338
- },
339
- slice: function( list, start, end ) {
340
- if( list === null ) return null
341
- return list.slice( start, end )
342
- },
343
- sortInternal: function( { list, fnSelection, compareFunctionWithFnSelection, compareFunction } ) {
314
+ return min;
315
+ },
316
+ removeAt: function (list, index, deleteCount) {
317
+ if (list === null) return null
318
+ const copiedList = list.slice()
319
+ copiedList.splice(index, deleteCount)
320
+ return copiedList
321
+ },
322
+ reverse: function (list) {
323
+ if (list === null) return null
324
+ return list.slice().reverse()
325
+ },
326
+ skip: function (list, count) {
327
+ if (list === null) return null
328
+ return list.slice(count)
329
+ },
330
+ skipWhile: function (list, fnCondition) {
331
+ if (list === null) return null
332
+
333
+ for (let i = 0; i < list.length; ++i) {
334
+ if (!fnCondition(list[i])) {
335
+ return list.slice(i)
336
+ }
337
+ }
338
+ return []
339
+ },
340
+ slice: function (list, start, end) {
341
+ if (list === null) return null
342
+ return list.slice(start, end)
343
+ },
344
+ sortInternal: function ({ list, fnSelection, compareFunctionWithFnSelection, compareFunction }) {
344
345
 
345
- if( list === null ) return null
346
+ if (list === null) return null
346
347
 
347
- if( !fnSelection ) return list.slice().sort( compareFunction )
348
+ if (!fnSelection) return list.slice().sort(compareFunction)
348
349
 
349
- const unsorted = new Array( list.length )
350
- for( let i = 0; i < list.length; ++i ) {
351
- unsorted[ i ] = { index: i, compareValue: fnSelection( list[ i ] ) }
352
- }
350
+ const unsorted = new Array(list.length)
351
+ for (let i = 0; i < list.length; ++i) {
352
+ unsorted[i] = { index: i, compareValue: fnSelection(list[i]) }
353
+ }
353
354
 
354
- const sorted = unsorted.sort( compareFunctionWithFnSelection );
355
+ const sorted = unsorted.sort(compareFunctionWithFnSelection);
355
356
 
356
- const resultArray = new Array( sorted.length )
357
- for( let i = 0; i < sorted.length; ++i ) {
358
- resultArray[ i ] = list[ sorted[ i ].index ]
359
- }
357
+ const resultArray = new Array(sorted.length)
358
+ for (let i = 0; i < sorted.length; ++i) {
359
+ resultArray[i] = list[sorted[i].index]
360
+ }
360
361
 
361
- return resultArray;
362
- },
363
- sort: function( list, fnSelection ) {
364
- return this.sortInternal( {
365
- list,
366
- fnSelection,
367
- compareFunctionWithFnSelection: function( a, b ) { return this.compare( a.compareValue, b.compareValue ) }.bind( this ),
368
- compareFunction: function( a, b ) { return this.compare( a, b ) }.bind( this )
369
- } )
370
- },
371
- sortDescending: function( list, fnSelection ) {
372
- return this.sortInternal( {
373
- list,
374
- fnSelection,
375
- compareFunctionWithFnSelection: function( a, b ) { return this.compare( b.compareValue, a.compareValue ); }.bind( this ),
376
- compareFunction: function( a, b ) { return this.compare( b, a ); }.bind( this )
377
- } )
378
- },
379
- sum: function( list, fnSelection ) {
380
- if( list === null ) return null;
381
- let sum = 0;
382
- if( fnSelection ) {
383
- for( let i = 0; i < list.length; ++i ) {
384
- const item = list[ i ];
385
- const value = fnSelection( item );
386
- if( value !== null )
387
- sum += value;
362
+ return resultArray;
363
+ },
364
+ sort: function (list, fnSelection) {
365
+ return this.sortInternal({
366
+ list,
367
+ fnSelection,
368
+ compareFunctionWithFnSelection: function (a, b) { return this.compare(a.compareValue, b.compareValue) }.bind(this),
369
+ compareFunction: function (a, b) { return this.compare(a, b) }.bind(this)
370
+ })
371
+ },
372
+ sortDescending: function (list, fnSelection) {
373
+ return this.sortInternal({
374
+ list,
375
+ fnSelection,
376
+ compareFunctionWithFnSelection: function (a, b) { return this.compare(b.compareValue, a.compareValue); }.bind(this),
377
+ compareFunction: function (a, b) { return this.compare(b, a); }.bind(this)
378
+ })
379
+ },
380
+ sum: function (list, fnSelection) {
381
+ if (list === null) return null;
382
+ let sum = 0;
383
+ if (fnSelection) {
384
+ for (let i = 0; i < list.length; ++i) {
385
+ const item = list[i];
386
+ const value = fnSelection(item);
387
+ if (value !== null)
388
+ sum += value;
389
+ }
388
390
  }
389
- }
390
- else {
391
- for( let i = 0; i < list.length; ++i ) {
392
- const value = list[ i ];
393
- if( value !== null )
394
- sum += value;
391
+ else {
392
+ for (let i = 0; i < list.length; ++i) {
393
+ const value = list[i];
394
+ if (value !== null)
395
+ sum += value;
396
+ }
395
397
  }
396
- }
397
- return sum;
398
- },
399
- take: function( list, count ) {
400
- if( list === null ) return null
401
- return list.slice( 0, count )
402
- },
403
- takeWhile: function( list, fnCondition ) {
404
- if( list === null ) return null;
405
-
406
- let i;
407
- for( i = 0; i < list.length; ++i ) {
408
- if( !fnCondition( list[ i ] ) ) {
409
- break
398
+ return sum;
399
+ },
400
+ take: function (list, count) {
401
+ if (list === null) return null
402
+ return list.slice(0, count)
403
+ },
404
+ takeWhile: function (list, fnCondition) {
405
+ if (list === null) return null;
406
+
407
+ let i;
408
+ for (i = 0; i < list.length; ++i) {
409
+ if (!fnCondition(list[i])) {
410
+ break
411
+ }
412
+ }
413
+ return list.slice(0, i);
414
+ },
415
+ union: function (listA, listB, fnSelection) {
416
+ if (listA === null && listB === null) return null
417
+ if (listA === null) return listB.slice()
418
+ if (listB === null) return listA.slice()
419
+
420
+ if (!fnSelection) {
421
+ return [...new Set(listA.concat(listB))]
410
422
  }
411
- }
412
- return list.slice( 0, i );
413
- },
414
- union: function( listA, listB, fnSelection ) {
415
- if( listA === null && listB === null ) return null
416
- if( listA === null ) return listB.slice()
417
- if( listB === null ) return listA.slice()
418
-
419
- if( !fnSelection ) {
420
- return [ ...new Set( listA.concat( listB ) ) ]
421
- }
422
423
 
423
- const resultArray = []
424
- const keys = []
424
+ const resultArray = []
425
+ const keys = []
425
426
 
426
- for( let i = 0; i < listA.length; ++i ) {
427
- const item = listA[ i ]
428
- const key = fnSelection( item )
429
- if( keys.indexOf( key ) === -1 ) {
430
- keys.push( key )
431
- resultArray.push( item )
427
+ for (let i = 0; i < listA.length; ++i) {
428
+ const item = listA[i]
429
+ const key = fnSelection(item)
430
+ if (keys.indexOf(key) === -1) {
431
+ keys.push(key)
432
+ resultArray.push(item)
433
+ }
432
434
  }
433
- }
434
435
 
435
- for( let i = 0; i < listB.length; ++i ) {
436
- const item = listB[ i ]
437
- const key = fnSelection( item )
438
- if( keys.indexOf( key ) === -1 ) {
439
- keys.push( key )
440
- resultArray.push( item )
436
+ for (let i = 0; i < listB.length; ++i) {
437
+ const item = listB[i]
438
+ const key = fnSelection(item)
439
+ if (keys.indexOf(key) === -1) {
440
+ keys.push(key)
441
+ resultArray.push(item)
442
+ }
441
443
  }
442
- }
443
444
 
444
- return resultArray;
445
+ return resultArray;
446
+ }
445
447
  }
446
448
  };