mirror of
https://github.com/swc-project/swc.git
synced 2024-12-26 15:12:08 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
// Loaded from https://deno.land/x/ramda@v0.27.2/source/move.js
|
|
|
|
|
|
import _curry3 from './internal/_curry3.js';
|
|
|
|
/**
|
|
* Move an item, at index `from`, to index `to`, in a list of elements.
|
|
* A new list will be created containing the new elements order.
|
|
*
|
|
* @func
|
|
* @memberOf R
|
|
* @since v0.27.1
|
|
* @category List
|
|
* @sig Number -> Number -> [a] -> [a]
|
|
* @param {Number} from The source index
|
|
* @param {Number} to The destination index
|
|
* @param {Array} list The list which will serve to realise the move
|
|
* @return {Array} The new list reordered
|
|
* @example
|
|
*
|
|
* R.move(0, 2, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['b', 'c', 'a', 'd', 'e', 'f']
|
|
* R.move(-1, 0, ['a', 'b', 'c', 'd', 'e', 'f']); //=> ['f', 'a', 'b', 'c', 'd', 'e'] list rotation
|
|
*/
|
|
var move = _curry3(function(from, to, list) {
|
|
var length = list.length;
|
|
var result = list.slice();
|
|
var positiveFrom = from < 0 ? length + from : from;
|
|
var positiveTo = to < 0 ? length + to : to;
|
|
var item = result.splice(positiveFrom, 1);
|
|
|
|
return positiveFrom < 0 || positiveFrom >= list.length
|
|
|| positiveTo < 0 || positiveTo >= list.length
|
|
? list
|
|
: []
|
|
.concat(result.slice(0, positiveTo))
|
|
.concat(item)
|
|
.concat(result.slice(positiveTo, list.length));
|
|
});
|
|
|
|
export default move;
|