@arrows/array
Version:
Functional tools for JS arrays
51 lines (41 loc) • 1.08 kB
text/typescript
import { flat } from "./index"
describe("Array flat", () => {
it("provides functional wrapper for Array.prototype.flat - depth one", () => {
const arr = [
[ ],
[ ],
]
const depth = 1
const result = flat(depth, arr)
const result2 = flat(depth)(arr)
// @ts-ignore
const expected = arr.flat(depth)
expect(result).toEqual(result2)
expect(result).toEqual(expected)
})
it("provides functional wrapper for Array.prototype.flat - higher depth", () => {
const arr = [
[
[ ],
[ ],
],
]
const depth = 2
const result = flat(depth, arr)
const result2 = flat(depth)(arr)
// @ts-ignore
const expected = arr.flat(depth)
expect(result).toEqual(result2)
expect(result).toEqual(expected)
})
it("provides functional wrapper for Array.prototype.flat - default depth (1)", () => {
const arr = [
[ ],
[ ],
]
const result = flat.one(arr)
// @ts-ignore
const expected = arr.flat()
expect(result).toEqual(expected)
})
})