deno.land / x / rambda@v9.1.1 / src / move.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { cloneList } from './_internals/cloneList.js'import { curry } from './curry.js'
function moveFn( fromIndex, toIndex, list){ if (fromIndex < 0 || toIndex < 0){ throw new Error('Rambda.move does not support negative indexes') } if (fromIndex > list.length - 1 || toIndex > list.length - 1) return list
const clone = cloneList(list) clone[ fromIndex ] = list[ toIndex ] clone[ toIndex ] = list[ fromIndex ]
return clone}
export const move = curry(moveFn)
rambda

Version Info

Tagged at
2 months ago