diff --git a/src/array/cluster.ts b/src/array/cluster.ts index 2bad738a..9b02fbbc 100644 --- a/src/array/cluster.ts +++ b/src/array/cluster.ts @@ -6,9 +6,9 @@ * // [[1, 2], [3, 4], [5, 6]] * ``` */ -export function cluster(list: readonly T[], size = 2): T[][] { - const clusterCount = Math.ceil(list.length / size) +export function cluster(array: readonly T[], size = 2): T[][] { + const clusterCount = Math.ceil(array.length / size) return new Array(clusterCount).fill(null).map((_c: null, i: number) => { - return list.slice(i * size, i * size + size) + return array.slice(i * size, i * size + size) }) } diff --git a/src/array/replace.ts b/src/array/replace.ts index 5887787a..3e042995 100644 --- a/src/array/replace.ts +++ b/src/array/replace.ts @@ -8,25 +8,25 @@ * ``` */ export function replace( - list: readonly T[], + array: readonly T[], newItem: T, match: (item: T, idx: number) => boolean, ): T[] { - if (!list) { + if (!array) { return [] } if (newItem === undefined) { - return [...list] + return [...array] } - for (let idx = 0; idx < list.length; idx++) { - const item = list[idx] + for (let idx = 0; idx < array.length; idx++) { + const item = array[idx] if (match(item, idx)) { return [ - ...list.slice(0, idx), + ...array.slice(0, idx), newItem, - ...list.slice(idx + 1, list.length), + ...array.slice(idx + 1, array.length), ] } } - return [...list] + return [...array] } diff --git a/src/array/replaceOrAppend.ts b/src/array/replaceOrAppend.ts index b3009287..b9ad4e22 100644 --- a/src/array/replaceOrAppend.ts +++ b/src/array/replaceOrAppend.ts @@ -12,28 +12,28 @@ * ``` */ export function replaceOrAppend( - list: readonly T[], + array: readonly T[], newItem: T, match: (a: T, idx: number) => boolean, ): T[] { - if (!list && !newItem) { + if (!array && !newItem) { return [] } if (!newItem) { - return [...list] + return [...array] } - if (!list) { + if (!array) { return [newItem] } - for (let idx = 0; idx < list.length; idx++) { - const item = list[idx] + for (let idx = 0; idx < array.length; idx++) { + const item = array[idx] if (match(item, idx)) { return [ - ...list.slice(0, idx), + ...array.slice(0, idx), newItem, - ...list.slice(idx + 1, list.length), + ...array.slice(idx + 1, array.length), ] } } - return [...list, newItem] + return [...array, newItem] } diff --git a/src/array/sift.ts b/src/array/sift.ts index bb3a6b76..f4143132 100644 --- a/src/array/sift.ts +++ b/src/array/sift.ts @@ -8,6 +8,6 @@ type Falsy = null | undefined | false | '' | 0 | 0n * // => [1, 2, 3] * ``` */ -export function sift(list: readonly (T | Falsy)[]): T[] { - return (list?.filter(x => !!x) as T[]) ?? [] +export function sift(array: readonly (T | Falsy)[]): T[] { + return (array?.filter(x => !!x) as T[]) ?? [] } diff --git a/src/array/toggle.ts b/src/array/toggle.ts index 6b22415d..a46cf41a 100644 --- a/src/array/toggle.ts +++ b/src/array/toggle.ts @@ -19,7 +19,7 @@ * ``` */ export function toggle( - list: readonly T[], + array: readonly T[], item: T, /** * Converts an item of type T item into a value that can be checked @@ -30,25 +30,25 @@ export function toggle( strategy?: 'prepend' | 'append' }, ): T[] { - if (!list && !item) { + if (!array && !item) { return [] } - if (!list) { + if (!array) { return [item] } if (!item) { - return [...list] + return [...array] } const matcher = toKey ? (x: T, idx: number) => toKey(x, idx) === toKey(item, idx) : (x: T) => x === item - const existing = list.find(matcher) + const existing = array.find(matcher) if (existing) { - return list.filter((x, idx) => !matcher(x, idx)) + return array.filter((x, idx) => !matcher(x, idx)) } const strategy = options?.strategy ?? 'append' if (strategy === 'append') { - return [...list, item] + return [...array, item] } - return [item, ...list] + return [item, ...array] }