@@ -42,15 +42,15 @@ export const copy: <T>(array: ArrayLike<T>) => T[] = Array.from;
4242// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4343// @ts -ignore duplicate identifier: This is the exported declaration, the implementation is below.
4444// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
45- export function isArray < T = unknown > ( value : readonly T [ ] | unknown ) : value is readonly T [ ] ;
45+ export function isArray ( value : unknown ) : value is readonly unknown [ ] ;
4646
4747/** @internal This implementation is for internal use only, the exported declaration is above */
4848// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4949// @ts -ignore duplicate identifier: This is the actual implementation, the exported declaration is above.
5050export const isArray : ( value : unknown ) => value is unknown [ ] = Array . isArray ;
5151
5252// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
53- export function isArrayLike < T > ( value : ArrayLike < T > | unknown ) : value is ArrayLike < T > {
53+ export function isArrayLike ( value : unknown ) : value is ArrayLike < unknown > {
5454 return (
5555 typeof value === "object" &&
5656 value != null &&
@@ -67,16 +67,6 @@ export function first<T>(array: ArrayLike<T>): T | null {
6767 return array . length === 0 ? null : ( array [ 0 ] as T ) ;
6868}
6969
70- /** @deprecated Use {@link first} instead. */
71- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
72- // @ts -ignore duplicate identifier: This is the exported declaration, the implementation is below.
73- export function head < T > ( array : ArrayLike < T > ) : T | null ;
74-
75- /** @internal This implementation is for internal use only, the exported declaration is above */
76- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
77- // @ts -ignore duplicate identifier: This is the actual implementation, the exported declaration is above.
78- export const head = first ;
79-
8070export function tail < T > ( array : ArrayLike < T > ) : T [ ] {
8171 return nativeSlice . call ( array , 1 ) as T [ ] ;
8272}
@@ -327,36 +317,6 @@ export function filterFn<T>(
327317 return array => nativeFilter . call ( array , predicate ) as T [ ] ;
328318}
329319
330- /** @deprecated This function is confusing, use {@link excludeFirst} instead,
331- * and invert the predicate. */
332- export function filterFirst < T > (
333- array : ArrayLike < T > ,
334- predicate : ( element : T , index : number ) => boolean
335- ) : T [ ] {
336- const result : T [ ] = [ ] ;
337- let i = 0 ;
338- for ( ; i < array . length ; ++ i ) {
339- const element = array [ i ] as T ;
340- if ( predicate ( element , i ) ) {
341- result . push ( element ) ;
342- } else {
343- break ;
344- }
345- }
346- for ( ++ i ; i < array . length ; ++ i ) {
347- result . push ( array [ i ] as T ) ;
348- }
349- return result ;
350- }
351-
352- /** @deprecated This function is confusing, use {@link excludeFirstFn} instead,
353- * and invert the predicate. */
354- export function filterFirstFn < T > (
355- predicate : ( element : T , index : number ) => boolean
356- ) : ( array : ArrayLike < T > ) => T [ ] {
357- return array => filterFirst ( array , predicate ) ;
358- }
359-
360320export function exclude < T , U > (
361321 array : ArrayLike < T | U > ,
362322 predicate : ( element : T | U ) => element is T
@@ -392,7 +352,20 @@ export function excludeFirst<T>(
392352 array : ArrayLike < T > ,
393353 predicate : ( element : T , index : number ) => boolean
394354) : T [ ] {
395- return filterFirst ( array , ( element , index ) => ! predicate ( element , index ) ) ;
355+ const result : T [ ] = [ ] ;
356+ let i = 0 ;
357+ for ( ; i < array . length ; ++ i ) {
358+ const element = array [ i ] as T ;
359+ if ( ! predicate ( element , i ) ) {
360+ result . push ( element ) ;
361+ } else {
362+ break ;
363+ }
364+ }
365+ for ( ++ i ; i < array . length ; ++ i ) {
366+ result . push ( array [ i ] as T ) ;
367+ }
368+ return result ;
396369}
397370
398371export function excludeFirstFn < T > (
@@ -1715,18 +1688,6 @@ export function uniqueAdjacentByHashFn<T>(
17151688 return array => uniqueAdjacentByHash ( array , hash ) ;
17161689}
17171690
1718- /** @deprecated Use [array-shuffle](https://npmjs.com/array-shuffle) instead. */
1719- export function shuffle < T > ( array : ArrayLike < T > ) : T [ ] {
1720- const result = copy ( array ) ;
1721- for ( let i = 0 ; i < array . length ; ++ i ) {
1722- const j = i + Math . floor ( Math . random ( ) * ( array . length - i ) ) ;
1723- const replacement = result [ j ] as T ;
1724- result [ j ] = result [ i ] as T ;
1725- result [ i ] = replacement ;
1726- }
1727- return result ;
1728- }
1729-
17301691export function sort ( array : ArrayLike < boolean > ) : boolean [ ] ;
17311692export function sort ( array : ArrayLike < number > ) : number [ ] ;
17321693export function sort ( array : ArrayLike < string > ) : string [ ] ;
0 commit comments