Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Move element(s) with one/multips arrays(s)

License

NotificationsYou must be signed in to change notification settings

jalal246/move-position

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Move element in a given array from one index to another ..with some extrafunctions.

npm install move-position

API

move

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.

Example -move

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

Compare elements of the first array with the rest of arrays.

functioncompare<T>(...args: T[][])

Example -compare

constdiff=compare(["a","b","c"],["b","c","e"]);>diff=["a"]

compareBoth

Compare elements in all inputs and gets the difference.

functioncompareBoth<T>(...args: T[][])

Example -compareBoth

constallDiff=compareBoth(["a","b","c"],["b","c","e"]);>allDiff=["a","e"]

flatten

Flatten an array

functionflatten<T>(unFlatten: T[])

Example -flatten

constflattened=flatten([[1,[2,3]],[1,[2,3]],0]);>flattened=[1,2,3,1,2,3,0]

toArray

Convert an input to array

functionflatten<T>(unFlatten: T[])

Example -toArray

constarray=toArray("a");>array=["a"]

Tests

npmtest

License

This project is licensed under theMIT

Related projects

  • 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 ⭐


[8]ページ先頭

©2009-2025 Movatter.jp