npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@felix-ongom/mixture

v1.0.0

Published

a simple library for removoving, inserting and moving eliements in an array given the indecies

Downloads

5

Readme

mixture

This is a javascript array library, simple and easy to use, It supports all kinds of array. it have methods like;

removeElement()

This is a method that takes two parameters,

  • first parameter being the array and the second parameter being
  • the index of the ement you want to remove from the array
  • it returns an array missing one item
removeElement([1,2,3], 1)
//[1,3]
insertElement()

It is a method that takes three parameters,

  • -first parameter being the array
  • -the second parameter is the elemrnt you want to insert
  • -third parameter is the index where you want it to appear
  • -it inserts the element at the end of the array if the index supplied is greater than or equal to the array length
  • it returns an array with one more element */
insertElement([1,2,3],20, 1)
//[1, 20, 2, 3]

insertElement([1,2,3],{num:20}, 10)
//[1, 2, 3, {num:20}]
moveElement()

It is a method that takes three parameters,

  • -first parameter being the array
  • -the second parameter is index of the elements you want to move
  • -third parameter is the index where you want it to appear
  • -it moves the element to the end of the array if the index supplied is greater than or equal to the array length */
moveElement([1, {two:2}, 3, 4, 5], 1, 3)
//[1,3,4,{two:2},5]
moveElementAcross(),

This is a method that takes two parameters,

  • -first parameter is an object with index of the element you are removing and array you are removing from.
  • -second parameter is an object with index you are inserting to and array you are inserting to
  • -it moves the element to the end of the array if the index supplied is greater than or equal to the array length in the second parameter
  • it returns an array of two array, firts one missing one element and
  • second one with one element more, */
 moveElementAcross(
    {index:1, arr1:[1,2,3,4]}
    {index:2, arr1:['one', 'two', 'three', 'four']}
 )
//[
    [2,3,4],
    ['one', 'two', 1, 'three', 'four']
  ]
randomChance()

Given the array

let arr = [0,1,2,4,6]
  • -randomChance takes in one mandatory array paramerter and return array with the same length

  • but with elements place randomly. Elements will appear by chance

  • -Note that some elements may appaer more thn once meanwhile other elements will not appear completely.

  • -it takes in the second parameter which is an inter number and it is the length of the result that you want back. if you don't supply it default to your array lenth.

  • -it takes in the third paramerter which is an array, The first element beng index of an element, and the second element being how much you want it to appear or dominate in the result and it ranges from 0 to 1,

let arr = [1,2,3,4,5,6,7,8,9,10]
randomChance(arr, 2)
//[2,4]

randomChance(arr, 10,[2, 0.2] )
//[3,5,3,4,5,6,8,6,7,10]
  • It can also take an array of array, [[0, 0.2], [3,0.4]], this mean you want elements at indeces 0 and 3 to dominate the result by 0.2 and 0.4 respective
let arr = [1,2,3,4,5,6,7,8,9,10]

randomChance(arr, 3) //[3,3, 1]

randomChance(arr, 5, [0, 0.2]) //[1, 4, 1, 3, 7]

randomChance(arr, 8, [[0,0.2],[3, 0.3]]) //[1, 4, 1, 4, 4 , 7, 3,10]
randomChoice()

It returns the same array with elements placed randomly with each element appearing once.

  • -takes in two parameter,
  • first paramert is mandatory and is an array
  • second paramert is optionanl and is the length of the array that you want back
let arr = [1,2,3,4,5]

randomChoice(arr, 4) //[5,3,4,1,2]
randomChoice(arr, 4) //[3 4,2,5]
randomChoice(arr, 4) //[5,2,4,3]
sort()

This method takes in two mandatory parameter ,first is an array of object and second is an objsct ,{id:1} describing how you want to sort.

let arr =[num:'one', num:'two', three:'three']
sort(arr, {num:1})
sort(arr, {num:-1})
  • -the key of the object is the field you want to look at when sorting and the value is either 1 or -1, 1 means ascending order while -1 means descending order.
Note: it can take in as many feilds , like {id:1, name:-1}