Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/compat/array/reverse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { times } from '../util/times';

describe('reverse', () => {
const largeArray = range(LARGE_ARRAY_SIZE).concat([null as any]);

Check warning on line 8 in src/compat/array/reverse.spec.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
const smallArray = [0, 1, 2, null];

it('should reverse `array`', () => {
Expand Down Expand Up @@ -84,4 +84,19 @@
expect(result).toEqual(['four', 3, 'two', 1]);
expect(result).toBe(array);
});

it('should work with array-like objects and `arguments`', () => {
const arrayLike = { 0: 'a', 1: 'b', 2: 'c', length: 3 };
const result = reverse(arrayLike);

expect(result).toBe(arrayLike);
expect(result).toEqual({ 0: 'c', 1: 'b', 2: 'a', length: 3 });
});

it('should return primitives unchanged', () => {
// @ts-expect-error - type mismatch
expect(Number(reverse(42))).toBe(42);
// @ts-expect-error - type mismatch
expect(Boolean(reverse(true))).toBe(true);
});
});
2 changes: 1 addition & 1 deletion src/compat/array/reverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* reverse(array);
* // => [3, 2, 1]
*/
export function reverse<L extends MutableList<any>>(array: RejectReadonly<L>): L;

Check warning on line 16 in src/compat/array/reverse.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

/**
* Reverses the elements of an array in place.
Expand Down Expand Up @@ -41,5 +41,5 @@
return array;
}

return array.reverse();
return Array.prototype.reverse.call(array);
}