- Notifications
You must be signed in to change notification settings - Fork0
Move element(s) with one/multips arrays(s)
License
jalal246/move-position
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Move element in a given array from one index to another ..with some extrafunctions.
npm install move-position
Moves element form one index to another with ability to fill each position andmutate the input array.
functionmove<T>( arr: T[] = [], movingMap: ArrayRange | ArrayRange[], Opts<T> ={})
ArrayRange
object contains:from: number
- Target index.to: number
- Destination index.
Opts
object contains:isMutate?: boolean
- Defaulttrue
- Mutate array input or create new one.isDuplicate?: boolean
- Defaultfalse
- Duplicate the traveled element or not.isSwap?: boolean
- Defaultfalse
- Swap between array elements.fill?: T
- Fill the original position with a value.
Trying default options:
constINPUT=["first","second","third","fourth"];constmovingMap=[{from:0,to:3}];constresult=move(INPUT,movingMap);>>result=["fourth","second","third","first"];
EnablesisDuplicate:true
:
constINPUT=["first","second","third","fourth"];constmovingMap=[{from:0,to:3}];constresult=move(INPUT,movingMap,{isDuplicate:true});//>>result=["first","second","third","first"];
With nullish:
constINPUT=["first","second","third","fourth"];constmovingMap=[{from:0,to:3}];constresult=move(INPUT,movingMap,{isDuplicate:false,isSwap:false,});>>result=[null,"second","third","first"];
With custom fill:
constINPUT=["first","second","third","fourth"];constmovingMap=[{from:0,to:3}];constresult=move(INPUT,movingMap,{fill:"emptiness"});>>result=["emptiness","second","third","first"];
Compare elements of the first array with the rest of arrays.
functioncompare<T>(...args: T[][])
constdiff=compare(["a","b","c"],["b","c","e"]);>diff=["a"]
Compare elements in all inputs and gets the difference.
functioncompareBoth<T>(...args: T[][])
constallDiff=compareBoth(["a","b","c"],["b","c","e"]);>allDiff=["a","e"]
Flatten an array
functionflatten<T>(unFlatten: T[])
constflattened=flatten([[1,[2,3]],[1,[2,3]],0]);>flattened=[1,2,3,1,2,3,0]
Convert an input to array
functionflatten<T>(unFlatten: T[])
constarray=toArray("a");>array=["a"]
npmtest
This project is licensed under theMIT
builderz - Zero Configuration JS bundler.
validate-access - Utility functions, parse and validate a given directory with multiple entries.
get-info - Utility functions for projects production.
textics &textics-stream - Counts lines,words, chars and spaces for a given string.
Support this package by giving it a Star ⭐
About
Move element(s) with one/multips arrays(s)