Skip to content

Commit

Permalink
feat: arrayMove; update readme: add shields; add coveralls
Browse files Browse the repository at this point in the history
  • Loading branch information
Rain120 committed Nov 22, 2019
1 parent e31bb0a commit 2292e38
Show file tree
Hide file tree
Showing 14 changed files with 738 additions and 504 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
npm ci
# npm run build --if-present
npm test
npm run coveralls
npm run changelog
env:
CI: true
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<h3 align="center">
<a href="https://github.com/Rain120/awesome-javascript-code-implementation">Awesome code implementation for Javascript</a>
<a href="https://github.com/Rain120/awesome-javascript-code-implementation">Awesome Javascript Code Implementation</a>
</h3>

<div align="center">

[![WATCH](https://img.shields.io/github/watchers/rain120/awesome-javascript-code-implementation?style=social)](https://github.com/Rain120/awesome-javascript-code-implementation/watchers) [![STAR](https://img.shields.io/github/stars/rain120/awesome-javascript-code-implementation?style=social)](https://github.com/Rain120/awesome-javascript-code-implementation/stargazers) [![FORK](https://img.shields.io/github/forks/rain120/awesome-javascript-code-implementation?style=social)](https://github.com/Rain120/awesome-javascript-code-implementation/network/members)

[![TEST](https://github.com/rain120/awesome-javascript-code-implementation/workflows/.github/workflows/test.yml/badge.svg)](https://github.com/Rain120/awesome-javascript-code-implementation/actions) ![LANGUAGES](https://img.shields.io/github/languages/top/rain120/awesome-javascript-code-implementation?style=flat-square)
[![VERSION](https://img.shields.io/github/package-json/v/rain120/awesome-javascript-code-implementation?style=flat-square)](https://github.com/Rain120/awesome-javascript-code-implementation/blob/master/package.json) [![LICENSE](https://img.shields.io/github/license/rain120/awesome-javascript-code-implementation?style=flat-square)](https://github.com/Rain120/awesome-javascript-code-implementation/blob/master/LICENSE) [![ISSUES](https://img.shields.io/github/issues/rain120/awesome-javascript-code-implementation?style=flat-square)](https://github.com/Rain120/awesome-javascript-code-implementation/issues) [![COMMIT](https://img.shields.io/github/last-commit/rain120/awesome-javascript-code-implementation?style=flat-square)](https://github.com/Rain120/awesome-javascript-code-implementation/commits/master)

</div>

## 😚 Welcome

Welcome to the Awesome Code Implementation.
Welcome to the Awesome Javascript Code Implementation.

[中文版本](zh-CN.md)

Expand All @@ -17,7 +26,7 @@ Welcome to the Awesome Code Implementation.
- Learn **Typescript**, **Jest** etc.
- Learning something about the **code implementation**.

#### 💻 规划
#### 💻 Plans

<img src="plans.svg">

Expand All @@ -43,7 +52,7 @@ We welcome all contributions. You can submit any ideas as [pull requests](https:

- [ ] Array

- [ ] isArray
- [x] isArray

- [ ] Object

Expand All @@ -65,6 +74,8 @@ We welcome all contributions. You can submit any ideas as [pull requests](https:

- [ ] curry

- [x] arrayMove

- [ ] Algorithm

- [ ] Sort
Expand Down
140 changes: 140 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
"description": "Awesome code implementation for Javascript",
"main": "index.js",
"scripts": {
"test": "jest --coverage",
"test": "jest",
"coveralls": "jest --coverage",
"test:watchAll": "jest --coverage --watchAll",
"lint-staged": "lint-staged",
"lint-staged:ts": "tslint -c ./tslint.json src/**/**.ts",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0"
},
"keywords": [
"awesome",
"javascript",
"code",
"implementation",
"code-implementation"
"code-implementation",
"sort",
"typescript"
],
"license": "MIT",
"bugs": {
Expand All @@ -43,6 +48,7 @@
"devDependencies": {
"@types/jest": "^24.0.23",
"conventional-changelog-cli": "^2.0.27",
"coveralls": "^3.0.8",
"husky": "^3.0.9",
"jest": "^24.9.0",
"lint-staged": "^9.4.3",
Expand Down
978 changes: 493 additions & 485 deletions plans.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plans.xmind
Binary file not shown.
7 changes: 7 additions & 0 deletions src/Array/arrayMove/README.md
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)
30 changes: 30 additions & 0 deletions src/Array/arrayMove/__tests__.ts
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']);
});
14 changes: 14 additions & 0 deletions src/Array/arrayMove/index.ts
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;
}
6 changes: 2 additions & 4 deletions src/call/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
* @Author: Rainy
* @Date: 2019-11-14 19:25:01
* @LastEditors: Rainy
* @LastEditTime: 2019-11-18 20:01:11
* @LastEditTime: 2019-11-22 11:19:18
*/

type ObjectMap<V> = {
[name: string]: V;
};
import { ObjectMap } from '../types/index';

// @ts-ignore
Function.prototype._call = function(context: ObjectMap<any>, ...arg: any): any {
Expand Down
15 changes: 15 additions & 0 deletions src/types/index.d.ts
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;
};
8 changes: 0 additions & 8 deletions src/utils/type.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
]
},
"rules": {
"align": [true, "statements"],
"arrow-parens": [true, "ban-single-arg-parens"],
"class-name": true,
"eofline": true,
Expand Down
Loading

0 comments on commit 2292e38

Please sign in to comment.