/
Array.cljs
513 lines (354 loc) · 15.7 KB
/
Array.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
(ns js.Array
"The JavaScript Array object is a global object that is used in
construction of arrays; which are high-level, list-like objects."
(:refer-clojure :exclude [concat filter find keys map pop reduce reverse some sort]))
(defn from
"Method.
The Array.from() method creates a new, shallow-copied Array instance
an array-like or iterable object.
`Array.from(arrayLike[, mapFn[, thisArg]])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from`"
[this & args]
(apply (-> this .-from) (concat [this] args)))
(defn is-array
"Method.
The Array.isArray() method determines whether the passed value
an `js.Array`.
`Array.isArray(value)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray`"
[this value]
(-> this (.isArray value)))
(defn observe
"Method.
The Array.observe() method was used for asynchronously observing
to Arrays, similar to `Object.observe()` for objects. It provided
stream of changes in order of occurrence. It's equivalent to
invoked with the accept type list [\\\"add\\\", \\\"update\\\", \\\"delete\\\",
However, this API has been deprecated and removed from Browsers.
can use the more general `js.Proxy` object instead.
`Array.observe(arr, callback)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/observe`"
[this arr callback]
(-> this (.observe arr callback)))
(defn of
"Method.
The Array.of() method creates a new Array instance from a variable
of arguments, regardless of number or type of the arguments.
`Array.of(element0[, element1[, ...[, elementN]]])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of`"
[this & args]
(apply (-> this .-of) (concat [this] args)))
(defn concat
"Method.
The concat() method is used to merge two or more arrays. This
does not change the existing arrays, but instead returns a new
`var new_array = old_array.concat([value1[, value2[, ...[, valueN]]]])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat`"
[this & args]
(apply (-> this .-concat) (concat [this] args)))
(defn copy-within
"Method.
The copyWithin() method shallow copies part of an array to another
in the same array and returns it without modifying its length.
`arr.copyWithin(target[, start[, end]])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin`"
[this & args]
(apply (-> this .-copyWithin) (concat [this] args)))
(defn entries
"Method.
The entries() method returns a new Array Iterator object that
the key/value pairs for each index in the array.
`array.entries()`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries`"
[this ]
(-> this (.entries)))
(defn every
"Method.
The every() method tests whether all elements in the array pass
test implemented by the provided function. It returns a Boolean
`arr.every(callback(element[, index[, array]])[, thisArg])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every`"
[this & args]
(apply (-> this .-every) (concat [this] args)))
(defn fill
"Method.
The fill() method fills (modifies) all the elements of an array
a start index (default zero) to an end index (default array length)
a static value. It returns the modified array.
`arr.fill(value[, start[, end]])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill`"
[this & args]
(apply (-> this .-fill) (concat [this] args)))
(defn filter
"Method.
The filter() method creates a new array with all elements that
the test implemented by the provided function.
`var newArray = arr.filter(callback(element[, index[, array]])[, thisArg])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter`"
[this & args]
(apply (-> this .-filter) (concat [this] args)))
(defn find
"Method.
The find() method returns the value of the first element in the
that satisfies the provided testing function. Otherwise `js.undefined`
returned.
`arr.find(callback(element[, index[, array]])[, thisArg])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find`"
[this & args]
(apply (-> this .-find) (concat [this] args)))
(defn find-index
"Method.
The findIndex() method returns the index of the first element
the array that satisfies the provided testing function. Otherwise,
returns -1, indicating that no element passed the test.
`arr.findIndex(callback(element[, index[, array]])[, thisArg])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex`"
[this & args]
(apply (-> this .-findIndex) (concat [this] args)))
(defn flat
"Method.
The flat() method creates a new array with all sub-array elements
into it recursively up to the specified depth.
`var newArray = arr.flat([depth]);`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat`"
[this & args]
(apply (-> this .-flat) (concat [this] args)))
(defn flat-map
"Method.
The flatMap() method first maps each element using a mapping
then flattens the result into a new array. It is identical to
`map()` followed by a `flat()` of depth 1, but flatMap() is often
useful, as merging both into one method is slightly more efficient.
`var new_array = arr.flatMap(function callback(currentValue[, index[, array]]) {
// return element for new_array
}[, thisArg])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap`"
[this & args]
(apply (-> this .-flatMap) (concat [this] args)))
(defn for-each
"Method.
The forEach() method executes a provided function once for each
element.
`arr.forEach(callback(currentValue [, index [, array]])[, thisArg]);`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach`"
[this & args]
(apply (-> this .-forEach) (concat [this] args)))
(defn includes
"Method.
The includes() method determines whether an array includes a
value among its entries, returning true or false as appropriate.
`arr.includes(valueToFind[, fromIndex])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes`"
[this & args]
(apply (-> this .-includes) (concat [this] args)))
(defn index-of
"Method.
The indexOf() method returns the first index at which a given
can be found in the array, or -1 if it is not present.
`arr.indexOf(searchElement[, fromIndex])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf`"
[this & args]
(apply (-> this .-indexOf) (concat [this] args)))
(defn join
"Method.
The join() method creates and returns a new string by concatenating
of the elements in an array (or an array-like object), separated
commas or a specified separator string. If the array has only
item, then that item will be returned without using the separator.
`arr.join([separator])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join`"
[this & args]
(apply (-> this .-join) (concat [this] args)))
(defn keys
"Method.
The keys() method returns a new Array Iterator object that contains
keys for each index in the array.
`arr.keys()`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys`"
[this ]
(-> this (.keys)))
(defn last-index-of
"Method.
The lastIndexOf() method returns the last index at which a given
can be found in the array, or -1 if it is not present. The array
searched backwards, starting at fromIndex.
`arr.lastIndexOf(searchElement[, fromIndex])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf`"
[this & args]
(apply (-> this .-lastIndexOf) (concat [this] args)))
(defn map
"Method.
The map() method creates a new array with the results of calling
provided function on every element in the calling array.
`var new_array = arr.map(function callback(currentValue[, index[, array]]) {
// Return element for new_array
}[, thisArg])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map`"
[this & args]
(apply (-> this .-map) (concat [this] args)))
(defn pop
"Method.
The pop() method removes the last element from an array and returns
element. This method changes the length of the array.
`arr.pop()`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop`"
[this ]
(-> this (.pop)))
(defn push
"Method.
The push() method adds one or more elements to the end of an
and returns the new length of the array.
`arr.push(element1[, ...[, elementN]])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/push`"
[this & args]
(apply (-> this .-push) (concat [this] args)))
(defn reduce
"Method.
The reduce() method executes a reducer function (that you provide)
each element of the array, resulting in a single output value.
`arr.reduce(callback(accumulator, currentValue[, index[, array]])[, initialValue])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/Reduce`"
[this & args]
(apply (-> this .-reduce) (concat [this] args)))
(defn reduce-right
"Method.
The reduceRight() method applies a function against an accumulator
each value of the array (from right-to-left) to reduce it to
single value.
`arr.reduceRight(callback(accumulator, currentValue[, index[, array]])[, initialValue])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/ReduceRight`"
[this & args]
(apply (-> this .-reduceRight) (concat [this] args)))
(defn reverse
"Method.
The reverse() method reverses an array in place. The first array
becomes the last, and the last array element becomes the first.
`a.reverse()`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse`"
[this ]
(-> this (.reverse)))
(defn shift
"Method.
The shift() method removes the first element from an array and
that removed element. This method changes the length of the array.
`arr.shift()`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift`"
[this ]
(-> this (.shift)))
(defn slice
"Method.
The slice() method returns a shallow copy of a portion of an
into a new array object selected from begin to end (end not included)
begin and end represent the index of items in that array. The
array will not be modified.
`arr.slice([begin[, end]])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice`"
[this & args]
(apply (-> this .-slice) (concat [this] args)))
(defn some
"Method.
The some() method tests whether at least one element in the array
the test implemented by the provided function. It returns a Boolean
`arr.some(callback(element[, index[, array]])[, thisArg])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some`"
[this & args]
(apply (-> this .-some) (concat [this] args)))
(defn sort
"Method.
The sort() method sorts the elements of an array in place and
the sorted array. The default sort order is built upon converting
elements into strings, then comparing their sequences of UTF-16
units values.
`arr.sort([compareFunction])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort`"
[this & args]
(apply (-> this .-sort) (concat [this] args)))
(defn splice
"Method.
The splice() method changes the contents of an array by removing
replacing existing elements and/or adding new elements in place.
`var arrDeletedItems = array.splice(start[, deleteCount[, item1[, item2[, ...]]]])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice`"
[this & args]
(apply (-> this .-splice) (concat [this] args)))
(defn to-locale-string
"Method.
The toLocaleString() method returns a string representing the
of the array. The elements are converted to Strings using their
methods and these Strings are separated by a locale-specific
(such as a comma “,”).
`arr.toLocaleString([locales[, options]]);`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toLocaleString`"
[this & args]
(apply (-> this .-toLocaleString) (concat [this] args)))
(defn to-source
"Method.
The toSource() method returns a string representing the source
of the array.
`arr.toSource()`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toSource`"
[this ]
(-> this (.toSource)))
(defn to-string
"Method.
The toString() method returns a string representing the specified
and its elements.
`arr.toString()`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString`"
[this ]
(-> this (.toString)))
(defn unshift
"Method.
The unshift() method adds one or more elements to the beginning
an array and returns the new length of the array.
`arr.unshift(element1[, ...[, elementN]])`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unshift`"
[this & args]
(apply (-> this .-unshift) (concat [this] args)))
(defn values
"Method.
The values() method returns a new Array Iterator object that
the values for each index in the array.
`arr.values()`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values`"
[this ]
(-> this (.values)))
(defn unobserve
"Method.
The Array.unobserve() method was used to remove observers set
`Array.observe()`, but has been deprecated and removed from Browsers.
can use the more general `js.Proxy` object instead.
`Array.unobserve(arr, callback)`
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/unobserve`"
[this arr callback]
(-> this (.unobserve arr callback)))
(defn length
"Property.
The Array constructor's length property whose value is 1."
[this]
(-> this (.length)))
(defn set-length!
"Property.
The Array constructor's length property whose value is 1."
[this val]
(aset this "length" val))
(defn prototype
"Property.
`js.Array` instances inherit from Array.prototype. As with all
you can change the constructor's prototype object to make changes
all `js.Array` instances. For example, you can add new methods
properties to extend all Array objects. This is used for polyfilling,
example.
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype`"
[this]
(-> this (.prototype)))
(defn set-prototype!
"Property.
`js.Array` instances inherit from Array.prototype. As with all
you can change the constructor's prototype object to make changes
all `js.Array` instances. For example, you can add new methods
properties to extend all Array objects. This is used for polyfilling,
example.
See also: `https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype`"
[this val]
(aset this "prototype" val))