Skip to content

Commit

Permalink
[system-a] utils/refs
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed May 16, 2024
1 parent 51fe580 commit 82a745f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/utils/refs.test.ts
Original file line number Diff line number Diff line change
@@ -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],
])
})
3 changes: 3 additions & 0 deletions src/utils/refs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function refs<A>(array: Array<A>, indexes: Array<number>): Array<A> {
return indexes.map((index) => array[index])
}

0 comments on commit 82a745f

Please sign in to comment.