UNPKG

33.2 kBTypeScriptView Raw
1/**
2 * The namespace for array-specific algorithms.
3 */
4export declare namespace ArrayExt {
5 /**
6 * Find the index of the first occurrence of a value in an array.
7 *
8 * @param array - The array-like object to search.
9 *
10 * @param value - The value to locate in the array. Values are
11 * compared using strict `===` equality.
12 *
13 * @param start - The index of the first element in the range to be
14 * searched, inclusive. The default value is `0`. Negative values
15 * are taken as an offset from the end of the array.
16 *
17 * @param stop - The index of the last element in the range to be
18 * searched, inclusive. The default value is `-1`. Negative values
19 * are taken as an offset from the end of the array.
20 *
21 * @returns The index of the first occurrence of the value, or `-1`
22 * if the value is not found.
23 *
24 * #### Notes
25 * If `stop < start` the search will wrap at the end of the array.
26 *
27 * #### Complexity
28 * Linear.
29 *
30 * #### Undefined Behavior
31 * A `start` or `stop` which is non-integral.
32 *
33 * #### Example
34 * ```typescript
35 * import { ArrayExt } from '@lumino/algorithm';
36 *
37 * let data = ['one', 'two', 'three', 'four', 'one'];
38 * ArrayExt.firstIndexOf(data, 'red'); // -1
39 * ArrayExt.firstIndexOf(data, 'one'); // 0
40 * ArrayExt.firstIndexOf(data, 'one', 1); // 4
41 * ArrayExt.firstIndexOf(data, 'two', 2); // -1
42 * ArrayExt.firstIndexOf(data, 'two', 2, 1); // 1
43 * ```
44 */
45 function firstIndexOf<T>(array: ArrayLike<T>, value: T, start?: number, stop?: number): number;
46 /**
47 * Find the index of the last occurrence of a value in an array.
48 *
49 * @param array - The array-like object to search.
50 *
51 * @param value - The value to locate in the array. Values are
52 * compared using strict `===` equality.
53 *
54 * @param start - The index of the first element in the range to be
55 * searched, inclusive. The default value is `-1`. Negative values
56 * are taken as an offset from the end of the array.
57 *
58 * @param stop - The index of the last element in the range to be
59 * searched, inclusive. The default value is `0`. Negative values
60 * are taken as an offset from the end of the array.
61 *
62 * @returns The index of the last occurrence of the value, or `-1`
63 * if the value is not found.
64 *
65 * #### Notes
66 * If `start < stop` the search will wrap at the front of the array.
67 *
68 * #### Complexity
69 * Linear.
70 *
71 * #### Undefined Behavior
72 * A `start` or `stop` which is non-integral.
73 *
74 * #### Example
75 * ```typescript
76 * import { ArrayExt } from '@lumino/algorithm';
77 *
78 * let data = ['one', 'two', 'three', 'four', 'one'];
79 * ArrayExt.lastIndexOf(data, 'red'); // -1
80 * ArrayExt.lastIndexOf(data, 'one'); // 4
81 * ArrayExt.lastIndexOf(data, 'one', 1); // 0
82 * ArrayExt.lastIndexOf(data, 'two', 0); // -1
83 * ArrayExt.lastIndexOf(data, 'two', 0, 1); // 1
84 * ```
85 */
86 function lastIndexOf<T>(array: ArrayLike<T>, value: T, start?: number, stop?: number): number;
87 /**
88 * Find the index of the first value which matches a predicate.
89 *
90 * @param array - The array-like object to search.
91 *
92 * @param fn - The predicate function to apply to the values.
93 *
94 * @param start - The index of the first element in the range to be
95 * searched, inclusive. The default value is `0`. Negative values
96 * are taken as an offset from the end of the array.
97 *
98 * @param stop - The index of the last element in the range to be
99 * searched, inclusive. The default value is `-1`. Negative values
100 * are taken as an offset from the end of the array.
101 *
102 * @returns The index of the first matching value, or `-1` if no
103 * matching value is found.
104 *
105 * #### Notes
106 * If `stop < start` the search will wrap at the end of the array.
107 *
108 * #### Complexity
109 * Linear.
110 *
111 * #### Undefined Behavior
112 * A `start` or `stop` which is non-integral.
113 *
114 * Modifying the length of the array while searching.
115 *
116 * #### Example
117 * ```typescript
118 * import { ArrayExt } from '@lumino/algorithm';
119 *
120 * function isEven(value: number): boolean {
121 * return value % 2 === 0;
122 * }
123 *
124 * let data = [1, 2, 3, 4, 3, 2, 1];
125 * ArrayExt.findFirstIndex(data, isEven); // 1
126 * ArrayExt.findFirstIndex(data, isEven, 4); // 5
127 * ArrayExt.findFirstIndex(data, isEven, 6); // -1
128 * ArrayExt.findFirstIndex(data, isEven, 6, 5); // 1
129 * ```
130 */
131 function findFirstIndex<T>(array: ArrayLike<T>, fn: (value: T, index: number) => boolean, start?: number, stop?: number): number;
132 /**
133 * Find the index of the last value which matches a predicate.
134 *
135 * @param object - The array-like object to search.
136 *
137 * @param fn - The predicate function to apply to the values.
138 *
139 * @param start - The index of the first element in the range to be
140 * searched, inclusive. The default value is `-1`. Negative values
141 * are taken as an offset from the end of the array.
142 *
143 * @param stop - The index of the last element in the range to be
144 * searched, inclusive. The default value is `0`. Negative values
145 * are taken as an offset from the end of the array.
146 *
147 * @returns The index of the last matching value, or `-1` if no
148 * matching value is found.
149 *
150 * #### Notes
151 * If `start < stop` the search will wrap at the front of the array.
152 *
153 * #### Complexity
154 * Linear.
155 *
156 * #### Undefined Behavior
157 * A `start` or `stop` which is non-integral.
158 *
159 * Modifying the length of the array while searching.
160 *
161 * #### Example
162 * ```typescript
163 * import { ArrayExt } from '@lumino/algorithm';
164 *
165 * function isEven(value: number): boolean {
166 * return value % 2 === 0;
167 * }
168 *
169 * let data = [1, 2, 3, 4, 3, 2, 1];
170 * ArrayExt.findLastIndex(data, isEven); // 5
171 * ArrayExt.findLastIndex(data, isEven, 4); // 3
172 * ArrayExt.findLastIndex(data, isEven, 0); // -1
173 * ArrayExt.findLastIndex(data, isEven, 0, 1); // 5
174 * ```
175 */
176 function findLastIndex<T>(array: ArrayLike<T>, fn: (value: T, index: number) => boolean, start?: number, stop?: number): number;
177 /**
178 * Find the first value which matches a predicate.
179 *
180 * @param array - The array-like object to search.
181 *
182 * @param fn - The predicate function to apply to the values.
183 *
184 * @param start - The index of the first element in the range to be
185 * searched, inclusive. The default value is `0`. Negative values
186 * are taken as an offset from the end of the array.
187 *
188 * @param stop - The index of the last element in the range to be
189 * searched, inclusive. The default value is `-1`. Negative values
190 * are taken as an offset from the end of the array.
191 *
192 * @returns The first matching value, or `undefined` if no matching
193 * value is found.
194 *
195 * #### Notes
196 * If `stop < start` the search will wrap at the end of the array.
197 *
198 * #### Complexity
199 * Linear.
200 *
201 * #### Undefined Behavior
202 * A `start` or `stop` which is non-integral.
203 *
204 * Modifying the length of the array while searching.
205 *
206 * #### Example
207 * ```typescript
208 * import { ArrayExt } from '@lumino/algorithm';
209 *
210 * function isEven(value: number): boolean {
211 * return value % 2 === 0;
212 * }
213 *
214 * let data = [1, 2, 3, 4, 3, 2, 1];
215 * ArrayExt.findFirstValue(data, isEven); // 2
216 * ArrayExt.findFirstValue(data, isEven, 2); // 4
217 * ArrayExt.findFirstValue(data, isEven, 6); // undefined
218 * ArrayExt.findFirstValue(data, isEven, 6, 5); // 2
219 * ```
220 */
221 function findFirstValue<T>(array: ArrayLike<T>, fn: (value: T, index: number) => boolean, start?: number, stop?: number): T | undefined;
222 /**
223 * Find the last value which matches a predicate.
224 *
225 * @param object - The array-like object to search.
226 *
227 * @param fn - The predicate function to apply to the values.
228 *
229 * @param start - The index of the first element in the range to be
230 * searched, inclusive. The default value is `-1`. Negative values
231 * are taken as an offset from the end of the array.
232 *
233 * @param stop - The index of the last element in the range to be
234 * searched, inclusive. The default value is `0`. Negative values
235 * are taken as an offset from the end of the array.
236 *
237 * @returns The last matching value, or `undefined` if no matching
238 * value is found.
239 *
240 * #### Notes
241 * If `start < stop` the search will wrap at the front of the array.
242 *
243 * #### Complexity
244 * Linear.
245 *
246 * #### Undefined Behavior
247 * A `start` or `stop` which is non-integral.
248 *
249 * Modifying the length of the array while searching.
250 *
251 * #### Example
252 * ```typescript
253 * import { ArrayExt } from '@lumino/algorithm';
254 *
255 * function isEven(value: number): boolean {
256 * return value % 2 === 0;
257 * }
258 *
259 * let data = [1, 2, 3, 4, 3, 2, 1];
260 * ArrayExt.findLastValue(data, isEven); // 2
261 * ArrayExt.findLastValue(data, isEven, 4); // 4
262 * ArrayExt.findLastValue(data, isEven, 0); // undefined
263 * ArrayExt.findLastValue(data, isEven, 0, 1); // 2
264 * ```
265 */
266 function findLastValue<T>(array: ArrayLike<T>, fn: (value: T, index: number) => boolean, start?: number, stop?: number): T | undefined;
267 /**
268 * Find the index of the first element which compares `>=` to a value.
269 *
270 * @param array - The sorted array-like object to search.
271 *
272 * @param value - The value to locate in the array.
273 *
274 * @param fn - The 3-way comparison function to apply to the values.
275 * It should return `< 0` if an element is less than a value, `0` if
276 * an element is equal to a value, or `> 0` if an element is greater
277 * than a value.
278 *
279 * @param start - The index of the first element in the range to be
280 * searched, inclusive. The default value is `0`. Negative values
281 * are taken as an offset from the end of the array.
282 *
283 * @param stop - The index of the last element in the range to be
284 * searched, inclusive. The default value is `-1`. Negative values
285 * are taken as an offset from the end of the array.
286 *
287 * @returns The index of the first element which compares `>=` to the
288 * value, or `length` if there is no such element. If the computed
289 * index for `stop` is less than `start`, then the computed index
290 * for `start` is returned.
291 *
292 * #### Notes
293 * The array must already be sorted in ascending order according to
294 * the comparison function.
295 *
296 * #### Complexity
297 * Logarithmic.
298 *
299 * #### Undefined Behavior
300 * Searching a range which is not sorted in ascending order.
301 *
302 * A `start` or `stop` which is non-integral.
303 *
304 * Modifying the length of the array while searching.
305 *
306 * #### Example
307 * ```typescript
308 * import { ArrayExt } from '@lumino/algorithm';
309 *
310 * function numberCmp(a: number, b: number): number {
311 * return a - b;
312 * }
313 *
314 * let data = [0, 3, 4, 7, 7, 9];
315 * ArrayExt.lowerBound(data, 0, numberCmp); // 0
316 * ArrayExt.lowerBound(data, 6, numberCmp); // 3
317 * ArrayExt.lowerBound(data, 7, numberCmp); // 3
318 * ArrayExt.lowerBound(data, -1, numberCmp); // 0
319 * ArrayExt.lowerBound(data, 10, numberCmp); // 6
320 * ```
321 */
322 function lowerBound<T, U>(array: ArrayLike<T>, value: U, fn: (element: T, value: U) => number, start?: number, stop?: number): number;
323 /**
324 * Find the index of the first element which compares `>` than a value.
325 *
326 * @param array - The sorted array-like object to search.
327 *
328 * @param value - The value to locate in the array.
329 *
330 * @param fn - The 3-way comparison function to apply to the values.
331 * It should return `< 0` if an element is less than a value, `0` if
332 * an element is equal to a value, or `> 0` if an element is greater
333 * than a value.
334 *
335 * @param start - The index of the first element in the range to be
336 * searched, inclusive. The default value is `0`. Negative values
337 * are taken as an offset from the end of the array.
338 *
339 * @param stop - The index of the last element in the range to be
340 * searched, inclusive. The default value is `-1`. Negative values
341 * are taken as an offset from the end of the array.
342 *
343 * @returns The index of the first element which compares `>` than the
344 * value, or `length` if there is no such element. If the computed
345 * index for `stop` is less than `start`, then the computed index
346 * for `start` is returned.
347 *
348 * #### Notes
349 * The array must already be sorted in ascending order according to
350 * the comparison function.
351 *
352 * #### Complexity
353 * Logarithmic.
354 *
355 * #### Undefined Behavior
356 * Searching a range which is not sorted in ascending order.
357 *
358 * A `start` or `stop` which is non-integral.
359 *
360 * Modifying the length of the array while searching.
361 *
362 * #### Example
363 * ```typescript
364 * import { ArrayExt } from '@lumino/algorithm';
365 *
366 * function numberCmp(a: number, b: number): number {
367 * return a - b;
368 * }
369 *
370 * let data = [0, 3, 4, 7, 7, 9];
371 * ArrayExt.upperBound(data, 0, numberCmp); // 1
372 * ArrayExt.upperBound(data, 6, numberCmp); // 3
373 * ArrayExt.upperBound(data, 7, numberCmp); // 5
374 * ArrayExt.upperBound(data, -1, numberCmp); // 0
375 * ArrayExt.upperBound(data, 10, numberCmp); // 6
376 * ```
377 */
378 function upperBound<T, U>(array: ArrayLike<T>, value: U, fn: (element: T, value: U) => number, start?: number, stop?: number): number;
379 /**
380 * Test whether two arrays are shallowly equal.
381 *
382 * @param a - The first array-like object to compare.
383 *
384 * @param b - The second array-like object to compare.
385 *
386 * @param fn - The comparison function to apply to the elements. It
387 * should return `true` if the elements are "equal". The default
388 * compares elements using strict `===` equality.
389 *
390 * @returns Whether the two arrays are shallowly equal.
391 *
392 * #### Complexity
393 * Linear.
394 *
395 * #### Undefined Behavior
396 * Modifying the length of the arrays while comparing.
397 *
398 * #### Example
399 * ```typescript
400 * import { ArrayExt } from '@lumino/algorithm';
401 *
402 * let d1 = [0, 3, 4, 7, 7, 9];
403 * let d2 = [0, 3, 4, 7, 7, 9];
404 * let d3 = [42];
405 * ArrayExt.shallowEqual(d1, d2); // true
406 * ArrayExt.shallowEqual(d2, d3); // false
407 * ```
408 */
409 function shallowEqual<T>(a: ArrayLike<T>, b: ArrayLike<T>, fn?: (a: T, b: T) => boolean): boolean;
410 /**
411 * Create a slice of an array subject to an optional step.
412 *
413 * @param array - The array-like object of interest.
414 *
415 * @param options - The options for configuring the slice.
416 *
417 * @returns A new array with the specified values.
418 *
419 * @throws An exception if the slice `step` is `0`.
420 *
421 * #### Complexity
422 * Linear.
423 *
424 * #### Undefined Behavior
425 * A `start`, `stop`, or `step` which is non-integral.
426 *
427 * #### Example
428 * ```typescript
429 * import { ArrayExt } from '@lumino/algorithm';
430 *
431 * let data = [0, 3, 4, 7, 7, 9];
432 * ArrayExt.slice(data); // [0, 3, 4, 7, 7, 9]
433 * ArrayExt.slice(data, { start: 2 }); // [4, 7, 7, 9]
434 * ArrayExt.slice(data, { start: 0, stop: 4 }); // [0, 3, 4, 7]
435 * ArrayExt.slice(data, { step: 2 }); // [0, 4, 7]
436 * ArrayExt.slice(data, { step: -1 }); // [9, 7, 7, 4, 3, 0]
437 * ```
438 */
439 function slice<T>(array: ArrayLike<T>, options?: slice.IOptions): T[];
440 /**
441 * The namespace for the `slice` function statics.
442 */
443 namespace slice {
444 /**
445 * The options for the `slice` function.
446 */
447 interface IOptions {
448 /**
449 * The starting index of the slice, inclusive.
450 *
451 * Negative values are taken as an offset from the end
452 * of the array.
453 *
454 * The default is `0` if `step > 0` else `n - 1`.
455 */
456 start?: number;
457 /**
458 * The stopping index of the slice, exclusive.
459 *
460 * Negative values are taken as an offset from the end
461 * of the array.
462 *
463 * The default is `n` if `step > 0` else `-n - 1`.
464 */
465 stop?: number;
466 /**
467 * The step value for the slice.
468 *
469 * This must not be `0`.
470 *
471 * The default is `1`.
472 */
473 step?: number;
474 }
475 }
476 /**
477 * An array-like object which supports item assignment.
478 */
479 type MutableArrayLike<T> = {
480 readonly length: number;
481 [index: number]: T;
482 };
483 /**
484 * Move an element in an array from one index to another.
485 *
486 * @param array - The mutable array-like object of interest.
487 *
488 * @param fromIndex - The index of the element to move. Negative
489 * values are taken as an offset from the end of the array.
490 *
491 * @param toIndex - The target index of the element. Negative
492 * values are taken as an offset from the end of the array.
493 *
494 * #### Complexity
495 * Linear.
496 *
497 * #### Undefined Behavior
498 * A `fromIndex` or `toIndex` which is non-integral.
499 *
500 * #### Example
501 * ```typescript
502 * import { ArrayExt } from from '@lumino/algorithm';
503 *
504 * let data = [0, 1, 2, 3, 4];
505 * ArrayExt.move(data, 1, 2); // [0, 2, 1, 3, 4]
506 * ArrayExt.move(data, 4, 2); // [0, 2, 4, 1, 3]
507 * ```
508 */
509 function move<T>(array: MutableArrayLike<T>, fromIndex: number, toIndex: number): void;
510 /**
511 * Reverse an array in-place.
512 *
513 * @param array - The mutable array-like object of interest.
514 *
515 * @param start - The index of the first element in the range to be
516 * reversed, inclusive. The default value is `0`. Negative values
517 * are taken as an offset from the end of the array.
518 *
519 * @param stop - The index of the last element in the range to be
520 * reversed, inclusive. The default value is `-1`. Negative values
521 * are taken as an offset from the end of the array.
522 *
523 * #### Complexity
524 * Linear.
525 *
526 * #### Undefined Behavior
527 * A `start` or `stop` index which is non-integral.
528 *
529 * #### Example
530 * ```typescript
531 * import { ArrayExt } from '@lumino/algorithm';
532 *
533 * let data = [0, 1, 2, 3, 4];
534 * ArrayExt.reverse(data, 1, 3); // [0, 3, 2, 1, 4]
535 * ArrayExt.reverse(data, 3); // [0, 3, 2, 4, 1]
536 * ArrayExt.reverse(data); // [1, 4, 2, 3, 0]
537 * ```
538 */
539 function reverse<T>(array: MutableArrayLike<T>, start?: number, stop?: number): void;
540 /**
541 * Rotate the elements of an array in-place.
542 *
543 * @param array - The mutable array-like object of interest.
544 *
545 * @param delta - The amount of rotation to apply to the elements. A
546 * positive value will rotate the elements to the left. A negative
547 * value will rotate the elements to the right.
548 *
549 * @param start - The index of the first element in the range to be
550 * rotated, inclusive. The default value is `0`. Negative values
551 * are taken as an offset from the end of the array.
552 *
553 * @param stop - The index of the last element in the range to be
554 * rotated, inclusive. The default value is `-1`. Negative values
555 * are taken as an offset from the end of the array.
556 *
557 * #### Complexity
558 * Linear.
559 *
560 * #### Undefined Behavior
561 * A `delta`, `start`, or `stop` which is non-integral.
562 *
563 * #### Example
564 * ```typescript
565 * import { ArrayExt } from '@lumino/algorithm';
566 *
567 * let data = [0, 1, 2, 3, 4];
568 * ArrayExt.rotate(data, 2); // [2, 3, 4, 0, 1]
569 * ArrayExt.rotate(data, -2); // [0, 1, 2, 3, 4]
570 * ArrayExt.rotate(data, 10); // [0, 1, 2, 3, 4]
571 * ArrayExt.rotate(data, 9); // [4, 0, 1, 2, 3]
572 * ArrayExt.rotate(data, 2, 1, 3); // [4, 2, 0, 1, 3]
573 * ```
574 */
575 function rotate<T>(array: MutableArrayLike<T>, delta: number, start?: number, stop?: number): void;
576 /**
577 * Fill an array with a static value.
578 *
579 * @param array - The mutable array-like object to fill.
580 *
581 * @param value - The static value to use to fill the array.
582 *
583 * @param start - The index of the first element in the range to be
584 * filled, inclusive. The default value is `0`. Negative values
585 * are taken as an offset from the end of the array.
586 *
587 * @param stop - The index of the last element in the range to be
588 * filled, inclusive. The default value is `-1`. Negative values
589 * are taken as an offset from the end of the array.
590 *
591 * #### Notes
592 * If `stop < start` the fill will wrap at the end of the array.
593 *
594 * #### Complexity
595 * Linear.
596 *
597 * #### Undefined Behavior
598 * A `start` or `stop` which is non-integral.
599 *
600 * #### Example
601 * ```typescript
602 * import { ArrayExt } from '@lumino/algorithm';
603 *
604 * let data = ['one', 'two', 'three', 'four'];
605 * ArrayExt.fill(data, 'r'); // ['r', 'r', 'r', 'r']
606 * ArrayExt.fill(data, 'g', 1); // ['r', 'g', 'g', 'g']
607 * ArrayExt.fill(data, 'b', 2, 3); // ['r', 'g', 'b', 'b']
608 * ArrayExt.fill(data, 'z', 3, 1); // ['z', 'z', 'b', 'z']
609 * ```
610 */
611 function fill<T>(array: MutableArrayLike<T>, value: T, start?: number, stop?: number): void;
612 /**
613 * Insert a value into an array at a specific index.
614 *
615 * @param array - The array of interest.
616 *
617 * @param index - The index at which to insert the value. Negative
618 * values are taken as an offset from the end of the array.
619 *
620 * @param value - The value to set at the specified index.
621 *
622 * #### Complexity
623 * Linear.
624 *
625 * #### Undefined Behavior
626 * An `index` which is non-integral.
627 *
628 * #### Example
629 * ```typescript
630 * import { ArrayExt } from '@lumino/algorithm';
631 *
632 * let data = [0, 1, 2];
633 * ArrayExt.insert(data, 0, -1); // [-1, 0, 1, 2]
634 * ArrayExt.insert(data, 2, 12); // [-1, 0, 12, 1, 2]
635 * ArrayExt.insert(data, -1, 7); // [-1, 0, 12, 1, 7, 2]
636 * ArrayExt.insert(data, 6, 19); // [-1, 0, 12, 1, 7, 2, 19]
637 * ```
638 */
639 function insert<T>(array: Array<T>, index: number, value: T): void;
640 /**
641 * Remove and return a value at a specific index in an array.
642 *
643 * @param array - The array of interest.
644 *
645 * @param index - The index of the value to remove. Negative values
646 * are taken as an offset from the end of the array.
647 *
648 * @returns The value at the specified index, or `undefined` if the
649 * index is out of range.
650 *
651 * #### Complexity
652 * Linear.
653 *
654 * #### Undefined Behavior
655 * An `index` which is non-integral.
656 *
657 * #### Example
658 * ```typescript
659 * import { ArrayExt } from '@lumino/algorithm';
660 *
661 * let data = [0, 12, 23, 39, 14, 12, 75];
662 * ArrayExt.removeAt(data, 2); // 23
663 * ArrayExt.removeAt(data, -2); // 12
664 * ArrayExt.removeAt(data, 10); // undefined;
665 * ```
666 */
667 function removeAt<T>(array: Array<T>, index: number): T | undefined;
668 /**
669 * Remove the first occurrence of a value from an array.
670 *
671 * @param array - The array of interest.
672 *
673 * @param value - The value to remove from the array. Values are
674 * compared using strict `===` equality.
675 *
676 * @param start - The index of the first element in the range to be
677 * searched, inclusive. The default value is `0`. Negative values
678 * are taken as an offset from the end of the array.
679 *
680 * @param stop - The index of the last element in the range to be
681 * searched, inclusive. The default value is `-1`. Negative values
682 * are taken as an offset from the end of the array.
683 *
684 * @returns The index of the removed value, or `-1` if the value
685 * is not contained in the array.
686 *
687 * #### Notes
688 * If `stop < start` the search will wrap at the end of the array.
689 *
690 * #### Complexity
691 * Linear.
692 *
693 * #### Example
694 * ```typescript
695 * import { ArrayExt } from '@lumino/algorithm';
696 *
697 * let data = [0, 12, 23, 39, 14, 12, 75];
698 * ArrayExt.removeFirstOf(data, 12); // 1
699 * ArrayExt.removeFirstOf(data, 17); // -1
700 * ArrayExt.removeFirstOf(data, 39, 3); // -1
701 * ArrayExt.removeFirstOf(data, 39, 3, 2); // 2
702 * ```
703 */
704 function removeFirstOf<T>(array: Array<T>, value: T, start?: number, stop?: number): number;
705 /**
706 * Remove the last occurrence of a value from an array.
707 *
708 * @param array - The array of interest.
709 *
710 * @param value - The value to remove from the array. Values are
711 * compared using strict `===` equality.
712 *
713 * @param start - The index of the first element in the range to be
714 * searched, inclusive. The default value is `-1`. Negative values
715 * are taken as an offset from the end of the array.
716 *
717 * @param stop - The index of the last element in the range to be
718 * searched, inclusive. The default value is `0`. Negative values
719 * are taken as an offset from the end of the array.
720 *
721 * @returns The index of the removed value, or `-1` if the value
722 * is not contained in the array.
723 *
724 * #### Notes
725 * If `start < stop` the search will wrap at the end of the array.
726 *
727 * #### Complexity
728 * Linear.
729 *
730 * #### Example
731 * ```typescript
732 * import { ArrayExt } from '@lumino/algorithm';
733 *
734 * let data = [0, 12, 23, 39, 14, 12, 75];
735 * ArrayExt.removeLastOf(data, 12); // 5
736 * ArrayExt.removeLastOf(data, 17); // -1
737 * ArrayExt.removeLastOf(data, 39, 2); // -1
738 * ArrayExt.removeLastOf(data, 39, 2, 3); // 3
739 * ```
740 */
741 function removeLastOf<T>(array: Array<T>, value: T, start?: number, stop?: number): number;
742 /**
743 * Remove all occurrences of a value from an array.
744 *
745 * @param array - The array of interest.
746 *
747 * @param value - The value to remove from the array. Values are
748 * compared using strict `===` equality.
749 *
750 * @param start - The index of the first element in the range to be
751 * searched, inclusive. The default value is `0`. Negative values
752 * are taken as an offset from the end of the array.
753 *
754 * @param stop - The index of the last element in the range to be
755 * searched, inclusive. The default value is `-1`. Negative values
756 * are taken as an offset from the end of the array.
757 *
758 * @returns The number of elements removed from the array.
759 *
760 * #### Notes
761 * If `stop < start` the search will conceptually wrap at the end of
762 * the array, however the array will be traversed front-to-back.
763 *
764 * #### Complexity
765 * Linear.
766 *
767 * #### Example
768 * ```typescript
769 * import { ArrayExt } from '@lumino/algorithm';
770 *
771 * let data = [14, 12, 23, 39, 14, 12, 19, 14];
772 * ArrayExt.removeAllOf(data, 12); // 2
773 * ArrayExt.removeAllOf(data, 17); // 0
774 * ArrayExt.removeAllOf(data, 14, 1, 4); // 1
775 * ```
776 */
777 function removeAllOf<T>(array: Array<T>, value: T, start?: number, stop?: number): number;
778 /**
779 * Remove the first occurrence of a value which matches a predicate.
780 *
781 * @param array - The array of interest.
782 *
783 * @param fn - The predicate function to apply to the values.
784 *
785 * @param start - The index of the first element in the range to be
786 * searched, inclusive. The default value is `0`. Negative values
787 * are taken as an offset from the end of the array.
788 *
789 * @param stop - The index of the last element in the range to be
790 * searched, inclusive. The default value is `-1`. Negative values
791 * are taken as an offset from the end of the array.
792 *
793 * @returns The removed `{ index, value }`, which will be `-1` and
794 * `undefined` if the value is not contained in the array.
795 *
796 * #### Notes
797 * If `stop < start` the search will wrap at the end of the array.
798 *
799 * #### Complexity
800 * Linear.
801 *
802 * #### Example
803 * ```typescript
804 * import { ArrayExt } from '@lumino/algorithm';
805 *
806 * function isEven(value: number): boolean {
807 * return value % 2 === 0;
808 * }
809 *
810 * let data = [0, 12, 23, 39, 14, 12, 75];
811 * ArrayExt.removeFirstWhere(data, isEven); // { index: 0, value: 0 }
812 * ArrayExt.removeFirstWhere(data, isEven, 2); // { index: 3, value: 14 }
813 * ArrayExt.removeFirstWhere(data, isEven, 4); // { index: -1, value: undefined }
814 * ```
815 */
816 function removeFirstWhere<T>(array: Array<T>, fn: (value: T, index: number) => boolean, start?: number, stop?: number): {
817 index: number;
818 value: T | undefined;
819 };
820 /**
821 * Remove the last occurrence of a value which matches a predicate.
822 *
823 * @param array - The array of interest.
824 *
825 * @param fn - The predicate function to apply to the values.
826 *
827 * @param start - The index of the first element in the range to be
828 * searched, inclusive. The default value is `-1`. Negative values
829 * are taken as an offset from the end of the array.
830 *
831 * @param stop - The index of the last element in the range to be
832 * searched, inclusive. The default value is `0`. Negative values
833 * are taken as an offset from the end of the array.
834 *
835 * @returns The removed `{ index, value }`, which will be `-1` and
836 * `undefined` if the value is not contained in the array.
837 *
838 * #### Notes
839 * If `start < stop` the search will wrap at the end of the array.
840 *
841 * #### Complexity
842 * Linear.
843 *
844 * #### Example
845 * ```typescript
846 * import { ArrayExt } from '@lumino/algorithm';
847 *
848 * function isEven(value: number): boolean {
849 * return value % 2 === 0;
850 * }
851 *
852 * let data = [0, 12, 23, 39, 14, 12, 75];
853 * ArrayExt.removeLastWhere(data, isEven); // { index: 5, value: 12 }
854 * ArrayExt.removeLastWhere(data, isEven, 2); // { index: 1, value: 12 }
855 * ArrayExt.removeLastWhere(data, isEven, 2, 1); // { index: -1, value: undefined }
856 * ```
857 */
858 function removeLastWhere<T>(array: Array<T>, fn: (value: T, index: number) => boolean, start?: number, stop?: number): {
859 index: number;
860 value: T | undefined;
861 };
862 /**
863 * Remove all occurrences of values which match a predicate.
864 *
865 * @param array - The array of interest.
866 *
867 * @param fn - The predicate function to apply to the values.
868 *
869 * @param start - The index of the first element in the range to be
870 * searched, inclusive. The default value is `0`. Negative values
871 * are taken as an offset from the end of the array.
872 *
873 * @param stop - The index of the last element in the range to be
874 * searched, inclusive. The default value is `-1`. Negative values
875 * are taken as an offset from the end of the array.
876 *
877 * @returns The number of elements removed from the array.
878 *
879 * #### Notes
880 * If `stop < start` the search will conceptually wrap at the end of
881 * the array, however the array will be traversed front-to-back.
882 *
883 * #### Complexity
884 * Linear.
885 *
886 * #### Example
887 * ```typescript
888 * import { ArrayExt } from '@lumino/algorithm';
889 *
890 * function isEven(value: number): boolean {
891 * return value % 2 === 0;
892 * }
893 *
894 * function isNegative(value: number): boolean {
895 * return value < 0;
896 * }
897 *
898 * let data = [0, 12, -13, -9, 23, 39, 14, -15, 12, 75];
899 * ArrayExt.removeAllWhere(data, isEven); // 4
900 * ArrayExt.removeAllWhere(data, isNegative, 0, 3); // 2
901 * ```
902 */
903 function removeAllWhere<T>(array: Array<T>, fn: (value: T, index: number) => boolean, start?: number, stop?: number): number;
904}