Last active
April 6, 2019 18:27
-
-
Save rosd89/a724a91a7282ff972a2da995f00f0383 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const splice = (arr = [], start = 0, deleteCount = 0, ...items) => { | |
| if (start < 0 || arr.length - 1 < start) { | |
| return [[], [...arr, ...items]]; | |
| } | |
| const arr1 = []; | |
| const arr2 = [...arr]; | |
| const result = []; | |
| for (let i = 0; i < arr.length; i++) { | |
| if (i == start) break; | |
| arr1.push(arr2.shift()); | |
| } | |
| if(deleteCount > 0) { | |
| for(let i = deleteCount; i > 0; i--) { | |
| result.push(arr2.shift()); | |
| } | |
| } | |
| return [[...result], [...arr1, ...items, ...arr2]]; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment