-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: rename
shift
to circularShift
- Loading branch information
1 parent
24307ef
commit a979308
Showing
6 changed files
with
45 additions
and
31 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
benchmarks/array/shift.bench.ts → benchmarks/array/circularShift.bench.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import * as _ from 'radashi' | ||
import { bench } from 'vitest' | ||
|
||
describe('shift', () => { | ||
describe('circularShift', () => { | ||
bench('with non-empty array', () => { | ||
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
_.shift(arr, 3) | ||
_.circularShift(arr, 3) | ||
}) | ||
|
||
bench('with empty array', () => { | ||
_.shift([], -3) | ||
_.circularShift([], -3) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
title: circularShift | ||
description: Shift array items by n steps | ||
--- | ||
|
||
### Usage | ||
|
||
Given a list of items, return an array that shift right n positions. | ||
|
||
```ts | ||
import * as _ from 'radashi' | ||
|
||
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
|
||
_.circularShift(arr, 3) // => [7, 8, 9, 1, 2, 3, 4, 5, 6] | ||
``` | ||
|
||
#### Negative index | ||
|
||
A negative index will shift the array left. | ||
|
||
```ts | ||
import * as _ from 'radashi' | ||
|
||
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
|
||
_.circularShift(arr, -3) // => [4, 5, 6, 7, 8, 9, 1, 2, 3] | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
tests/array/shift.test.ts → tests/array/circularShift.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
import * as _ from 'radashi' | ||
|
||
describe('shift', () => { | ||
describe('circularShift', () => { | ||
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] | ||
test('should shift array right 3 positions', () => { | ||
const result = _.shift(arr, 3) | ||
const result = _.circularShift(arr, 3) | ||
expect(result).toEqual([7, 8, 9, 1, 2, 3, 4, 5, 6]) | ||
}) | ||
test('should shift array left 3 positions', () => { | ||
const result = _.shift(arr, -3) | ||
const result = _.circularShift(arr, -3) | ||
expect(result).toEqual([4, 5, 6, 7, 8, 9, 1, 2, 3]) | ||
}) | ||
test('should shift array right 6 positions', () => { | ||
const result = _.shift(arr, 15) | ||
const result = _.circularShift(arr, 15) | ||
expect(result).toEqual([4, 5, 6, 7, 8, 9, 1, 2, 3]) | ||
}) | ||
test('should shift array left 6 positions', () => { | ||
const result = _.shift(arr, -15) | ||
const result = _.circularShift(arr, -15) | ||
expect(result).toEqual([7, 8, 9, 1, 2, 3, 4, 5, 6]) | ||
}) | ||
test('should keep array as is', () => { | ||
const result = _.shift(arr, 0) | ||
const result = _.circularShift(arr, 0) | ||
expect(result).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) | ||
}) | ||
test('should keep array as is', () => { | ||
const result = _.shift(arr, 9) | ||
const result = _.circularShift(arr, 9) | ||
expect(result).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) | ||
}) | ||
test('should return empty array', () => { | ||
const results = _.shift([], 0) | ||
const results = _.circularShift([], 0) | ||
expect(results).toEqual([]) | ||
}) | ||
test('should return empty array', () => { | ||
const results = _.shift([], 10) | ||
const results = _.circularShift([], 10) | ||
expect(results).toEqual([]) | ||
}) | ||
}) |