import { List } from '../types' ; import { curry2 } from '@typed/functions' ; import { length } from '../length' ; name export const endsWith = curry2 ( __endsWith ) ; export type EndsWith = { < A > ( expected , list ) : boolean ; < A > ( expected ) : ( list : List < A > ) => boolean ; } ; function __endsWith < A > ( expected , list ) { const itemCount = length ( list ) ; const expectedCount = length ( expected ) ; const startingIndex = itemCount - expectedCount ; if ( startingIndex < 0 ) return false ; for ( let i = 0 ; i < expectedCount ; ++ i ) if ( expected [ i ] !== list [ startingIndex + i ] ) return false ; return true ; }