Skip to content

at(index, xs) curry

入参

参数类型必填说明
indexnumber可为负数
xsArray<any>--

返回

ts
any | undefined;

示例

ts
import { at } from "./at";

describe("at", () => {
  test("normal", () => {
    const xs = [0, 1, 2, 3];
    const first = at(0);
    const x = first(xs);
    expect(x).toBe(0);
    expect(at(-1)(xs)).toBe(3);
    expect(at(1)(xs)).toBe(1);
    expect(at(-4)(xs)).toBe(0);
    expect(at(-10)(xs)).toBe(undefined);
  });
});