swc/bundler/tests/.cache/deno/4d06f66f9ce1249dbe8735b482ed30a1d8f6f01c.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

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;