diff --git a/index.test.ts b/index.test.ts index 84f3a297..ff0f92c7 100644 --- a/index.test.ts +++ b/index.test.ts @@ -41,6 +41,7 @@ import { product, remove, removeFirst, + reverse, scan, scan1, scanRight, @@ -90,6 +91,12 @@ test("empty", t => { t.false(empty([1, 2, 3])); }); +test("reverse", t => { + const a = [1, 2, 4, 3]; + t.deepEqual(reverse(a), [3, 4, 2, 1]); + t.deepEqual(a, [1, 2, 4, 3]); // Ensure original array is untouched. +}); + test("slice", t => { t.deepEqual(slice([1, 2, 3, 4], 1), [2, 3, 4]); t.deepEqual(slice([1, 2, 3, 4, 5], 1, 4), [2, 3, 4]); diff --git a/index.ts b/index.ts index a3a4d9c4..ca0a0984 100644 --- a/index.ts +++ b/index.ts @@ -107,7 +107,7 @@ export function notEmpty(array: ArrayLike): boolean { } export function reverse(array: ArrayLike): T[] { - return nativeReverse.call(array); + return nativeReverse.call(copy(array)); } export function slice(array: ArrayLike, start?: number, end?: number): T[] {