Skip to content

Commit

Permalink
Update desc with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jalal246 committed Mar 27, 2020
1 parent 2aa5481 commit fe0e5bd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
47 changes: 42 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ npm install move-position

```js
/**
* Move element form/to
* Moves element form/to index.
*
* @param {Array} [arr=[]]
* @param {number} from
Expand All @@ -32,10 +32,19 @@ const result = move(input, 0, 2);
// ["b", "c", "a"];
```

## moveMultiple
## moveMultiArr

```js
const modifiedArr = moveMultiple([arr1, arr2, ...], from, to, isMutate);
/**
* Moves the same index in multiple arrays
*
* @param {Array} [arr=[]] Array contain arrays to be changed
* @param {number} from - targeted index
* @param {number} to - targeted index
* @param {boolean} [isMutate=true]
* @returns {Array}
*/
const modifiedArr = moveMultiArr([arr1, arr2, ...], from, to, isMutate);
```

### Example(2)
Expand All @@ -44,14 +53,42 @@ const modifiedArr = moveMultiple([arr1, arr2, ...], from, to, isMutate);
const input1 = ["a1", "b1", "c1"];
const input2 = ["a2", "b2", "c2"];

const total = [input1, input2];
const allInputs = [input1, input2];

const result = moveMultiple(total, 2, 0);
const result = moveMultiArr(allInputs, 2, 0);

// result[0] > ["c1", "a1", "b1"];
// result[1] > ["c2", "a2", "b2"];
```

## moveMultiIndex

```js
/**
* Moves multiple indexes in the same array.
*
* @param {Array} [arr=[]]
* @param {{ from, to }[]} movingMap
* @returns {Array} new Array with index changes
*/
const modifiedArr = moveMultiIndex(arr, [{from, to}, ...]);
```

### Example(3)

```js
const input = ["a", "b", "c"];

const movingMap = [
{ from: 0, to: 2 },
{ from: 2, to: 1 }
];

const result = moveMultiIndex(input, movingMap);

// result > [ 'a', 'c', 'a' ]
```

### Related projects

- [packageSorter](https://github.com/jalal246/packageSorter) - Sorting packages
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ function move(arr = [], from, to, isMutate = true) {
}

/**
* Moves multiple arrays element from the same index.
* Moves the same index in multiple arrays
*
* @param {Array} [arr=[]] array contain arrays to be changed
* @param {number} from
* @param {number} to
* @param {Array} [arr=[]] Array contain arrays to be changed
* @param {number} from - targeted index
* @param {number} to - targeted index
* @param {boolean} [isMutate=true]
* @returns {Array}
*/
Expand Down

0 comments on commit fe0e5bd

Please sign in to comment.