UNPKG

@extra-array/move-within-update

Version:
58 lines (43 loc) 1.78 kB
Moves part of array within. [:package:](https://www.npmjs.com/package/@extra-array/move-within-update) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/move-within-update) [:vhs:](https://asciinema.org/a/342303) [:moon:](https://www.npmjs.com/package/@extra-array/move-within-update.min) [:scroll:](https://unpkg.com/@extra-array/move-within-update/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Alternatives: [moveWithin], [moveWithin$].<br> > Similar: [copy], [copyWithin], [moveWithin]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.moveWithin$(x, [j], [i], [I]); // x: an array (updated) // j: write index (0) // i: read start index (0) // I: read end index (X) // → x ``` ```javascript const array = require("extra-array"); var x = [1, 2, 3, 4, 5, 6]; array.moveWithin$(x, 0, 1, 3); // [ 2, 3, 1, 4, 5, 6 ] (2,3 to left) x; // [ 2, 3, 1, 4, 5, 6 ] var x = [1, 2, 3, 4, 5, 6]; array.moveWithin$(x, 6, 3, 5); // [ 1, 2, 3, 6, 4, 5 ] (4,5 to right) ``` <br> <br> ## References - [Array.prototype.copyWithin: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/copyWithin) - [immutable-iterable-prototype: @azu](https://github.com/azu/immutable-iterable-prototype) - [array-move: @sindresorhus](https://www.npmjs.com/package/array-move) [moveWithin]: https://github.com/nodef/extra-array/wiki/moveWithin [moveWithin$]: https://github.com/nodef/extra-array/wiki/moveWithin$ [copy]: https://github.com/nodef/extra-array/wiki/copy [copyWithin]: https://github.com/nodef/extra-array/wiki/copyWithin