内容简介:Move element in given array form index-A to index-BThis project is licensed under the
move-position
Move element in given array form index-A to index-B
npm install move-position
move
/** * Moves element form/to index. * * @param {Array} [arr=[]] * @param {number} from * @param {number} to * @param {boolean} [isMutate=true] * @returns {Array} */ const modifiedArr = move(arr, from, to, isMutate);
Example(1)
const input = ["a", "b", "c"]; // move element form index=0, to index=2 const result = move(input, 0, 2); // ["b", "c", "a"];
moveMultiArr
/** * 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)
const input1 = ["a1", "b1", "c1"]; const input2 = ["a2", "b2", "c2"]; const inputs = [input1, input2]; const result = moveMultiArr(inputs, 2, 0); // result[0] > ["c1", "a1", "b1"]; // result[1] > ["c2", "a2", "b2"];
moveMultiIndex
/** * Moves multiple indexes in the same array * * @param {Array} [arr=[]] * @param {Object[]} movingMap * @returns {Array} new Array with index changes */ const modifiedArr = moveMultiIndex(arr, [{from, to}, ...]);
Example(3)
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 - Sorting packages for monorepos production.
-
builderz - Building your project with zero config.
-
corename - Extracts package name.
-
get-info - Utility functions for projects production.
-
textics & textics-stream - Counts lines, words, chars and spaces for a given string.
Tests
npm test
License
This project is licensed under the GPL-3.0 License
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
深入浅出React和Redux
程墨 / 机械工业出版社 / 2017-4-28 / 69
本书作者是资深开发人员,有过多年的开发经验,总结了自己使用React和Redux的实战经验,系统分析React和Redux结合的优势,与开发技巧,为开发大型系统提供参考。主要内容包括:React的基础知识、如何设计易于维护的React组件、如何使用Redux控制数据流、React和Redux的相结合的方式、同构的React和Redux架构、React和Redux的性能优化、组件的测试等。一起来看看 《深入浅出React和Redux》 这本书的介绍吧!