diff --git a/src/utils/refs.test.ts b/src/utils/refs.test.ts new file mode 100644 index 0000000..30167d3 --- /dev/null +++ b/src/utils/refs.test.ts @@ -0,0 +1,12 @@ +import assert from "node:assert" +import { test } from "node:test" +import { refs } from "./refs.js" + +test("refs", () => { + assert.deepStrictEqual(refs([0, 1, 2, 3, 4, 5], [1, 3, 5]), [1, 3, 5]) + assert.deepStrictEqual(refs([[0], [1], [2], [3], [4], [5]], [1, 3, 5]), [ + [1], + [3], + [5], + ]) +}) diff --git a/src/utils/refs.ts b/src/utils/refs.ts new file mode 100644 index 0000000..a22010a --- /dev/null +++ b/src/utils/refs.ts @@ -0,0 +1,3 @@ +export function refs(array: Array, indexes: Array): Array { + return indexes.map((index) => array[index]) +}