-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: arrayMove; update readme: add shields; add coveralls
- Loading branch information
Showing
14 changed files
with
738 additions
and
504 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ jobs: | |
npm ci | ||
# npm run build --if-present | ||
npm test | ||
npm run coveralls | ||
npm run changelog | ||
env: | ||
CI: true |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Binary file not shown.
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,7 @@ | ||
### 原理 | ||
|
||
通过 `splice`方法去复制需要移动的数组元素,并拼接新数组。 | ||
|
||
### 参考 | ||
|
||
[splice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) |
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,30 @@ | ||
/* | ||
* @Author: Rainy | ||
* @Date: 2019-11-14 19:25:01 | ||
* @LastEditors: Rainy | ||
* @LastEditTime: 2019-11-22 16:26:40 | ||
*/ | ||
|
||
import { arrayMove } from '.'; | ||
|
||
const input = ['a', 'b', 'c', 'd', 'e', 'f']; | ||
|
||
test(`arrayMove(['a', 'b', 'c', 'd', 'e', 'f'], -1, 0)should ['f', 'a', 'b', 'c', 'd', 'e']`, () => { | ||
expect(arrayMove(input, -1, 0)).toEqual(['f', 'a', 'b', 'c', 'd', 'e']); | ||
}); | ||
|
||
test(`arrayMove(['a', 'b', 'c', 'd', 'e', 'f'], -1, 2) should ['a', 'b', 'f', 'c', 'd', 'e']`, () => { | ||
expect(arrayMove(input, -1, 2)).toEqual(['a', 'b', 'f', 'c', 'd', 'e']); | ||
}); | ||
|
||
test(`arrayMove(['a', 'b', 'c', 'd', 'e', 'f'], -1, 2) should ['a', 'b', 'f', 'c', 'd', 'e']`, () => { | ||
expect(arrayMove(input, -1, 2)).toEqual(['a', 'b', 'f', 'c', 'd', 'e']); | ||
}); | ||
|
||
test(`arrayMove(['a', 'b', 'c', 'd', 'e', 'f'], -1, -3) should ['a', 'b', 'c', 'f', 'd', 'e']`, () => { | ||
expect(arrayMove(input, -1, -3)).toEqual(['a', 'b', 'c', 'f', 'd', 'e']); | ||
}); | ||
|
||
test(`arrayMove(['a', 'b', 'c', 'd', 'e', 'f'], 1, 3) should ['a', 'c', 'd', 'b', 'e', 'f']`, () => { | ||
expect(arrayMove(input, 1, 3)).toEqual(['a', 'c', 'd', 'b', 'e', 'f']); | ||
}); |
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,14 @@ | ||
/* | ||
* @Author: Rainy | ||
* @Date: 2019-11-14 19:25:01 | ||
* @LastEditors: Rainy | ||
* @LastEditTime: 2019-11-22 17:43:05 | ||
*/ | ||
|
||
import { ArrayMap } from '../../types/index'; | ||
|
||
export function arrayMove(array: ArrayMap, from: number, to: number): ArrayMap { | ||
array = array.slice(); | ||
array.splice(to < 0 ? array.length + to : to, 0, array.splice(from, 1)[0]); | ||
return array; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
/* | ||
* @Author: Rainy | ||
* @Date: 2019-11-14 19:55:36 | ||
* @LastEditors: Rainy | ||
* @LastEditTime: 2019-11-22 15:30:14 | ||
*/ | ||
|
||
export class ClassType {} | ||
|
||
export type ArrayMap = unknown[]; | ||
|
||
export type ObjectMap<V> = { | ||
[name: string]: V; | ||
}; |
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
Oops, something went wrong.