Type alias InitialAndLast<Input>

InitialAndLast<Input>: Input extends readonly [...(infer Initial), infer Last] ? readonly [Initial, Last] : Input extends EmptyArray | EmptyString ? readonly [Input, undefined] : Input extends `${infer Initial}${infer Rest}` ? readonly [`${Rest extends EmptyString ? EmptyString : Initial}${InitialAndLast<Rest>[0]}`, `${Rest extends EmptyString ? Initial : InitialAndLast<Rest>[1]}`] : readonly [Input, Input[number] | undefined]

Get a couple with the initial and last values of an array or string.

Example

const array = ["🟢", "🟩", "💚"];
const initialAndLast: InitialAndLast<typeof array> = [["🟢", "🟩"], "💚"];

Type Parameters

  • Input extends ArrayLike<unknown>