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

alisa.array

v0.0.3

Published

Advanced functions that are not in JavaScript's default array functions

Downloads

16

Readme

Alisa Logo

Package Name Package size Version License

NPM

Source file

Creator(s)

Social media accounts

How is it used and what are its features?

  • Let's first look at how to use:
// If you created a regular JavaScript file (without Node.js)
// You can use it like this

import _ from "alisa.array"
// You can give any name you want here, we will not use it anyway

// But if you have created Node.js file, you should use it like this
require("alisa.array")


// After doing this, you can now access all the features. For example:
const array = [1, 2, 3, 4, 5];

const filterAndMap = array.filterAndMap(
    // First we filter which numbers to get
    (number) => number >= 3,

    // Then we determine what to do with these numbers
    (number) => number * number
)

// If we print this to the console it will look something like this:
console.log(filterAndMap);
// [9, 16, 25]
  • If your code compiler says something like "No such function" after typing "filterAndMap" or something else, ignore it, if you have imported the module correctly it will work.
  • The module has many more features like this. Below are the features added thanks to this module, what they all do and an example for each. If you think you don't need it, you can skip here.

Here are all the features:

  • sameArray() => Checks if the array entered in the function is the same as the array.
const array = [1, 2, 3, 4, 5];

console.log(array.sameArray([1, 2, 3])) // false;
console.log(array.sameArray([1, 2, 3, 4, 5])) // true
  • allIndexOf() => Returns all index values that satisfy the value you entered.
const array = [1, 2, 3, 4, 5, 1, 2];

console.log(array.allIndexOf(1)) // [0, 5];
console.log(array.allIndexOf(6)) // -1
  • findIndexAll() => Returns all index values that satisfy the function you entered.
const array = [1, 2, 3, 4, 5];

console.log(array.findIndexAll(number => number > 2)) // [2, 3, 4];
console.log(array.findIndexAll(number => number < 0)) // -1
  • concatAll() => Returns a new array by concatenating all the arrays you entered in it.
const array = [1, 2, 3, 4, 5];

console.log(array.concatAll([6, 7], [8, 9, 10]))
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  • filterAndMap() => Saves time and memory by performing both filtering and mapping at the same time.
const array = [1, 2, 3, 4, 5];

console.log(array.filterAndMap(
    (number) => number <= 2,
    (number) => number + number
))
// [2, 4]
  • pushWithSort() => Adds the value you entered sequentially into the array.
const array = [1, 2, 4, 5];

array.pushWithSort(3);

console.log(array)
// [1, 2, 3, 4, 5]
  • swap() => Swaps two values in array. The entered values are index values.
const array = [4, 2, 3, 1, 5];

array.swap(0, 3);

console.log(array)
// [1, 2, 3, 4, 5]
  • count() => Counts how many times the value you entered occurs in the array. If you entered a function, the function returns the number of appropriate numbers.
const array = [1, 2, 3, 4, 5];

console.log(array.count(1)) // 1

console.log(array.count(
    (number, index, thisArray) => {
      return number >= 3
    })
) // 3
  • shuffle() => Randomly shuffles elements in an array.
const array = [1, 2, 3, 4, 5];

console.log(array.shuffle())
// [5, 3, 4, 1, 2]

console.log(array.shuffle())
// [2, 5, 3, 4, 1]
  • similar() => Returns an array of differences between the array you entered and the original array.
const array = [1, 2, 3, 4, 5];

console.log(array.similar([3, 4, 5, 6, 7]))
// [3, 4, 5]
  • similar() => Returns an array of similarities between the array you entered and the original array.
const array = [1, 2, 3, 4, 5];

console.log(array.similar([3, 4, 5, 6, 7]))
// [3, 4, 5]
  • removeDuplicate() => Removes all duplicate values in the array.
const array = [1, 2, 3, 4, 5, 1, 5, 4, 3, 2];

console.log(array.removeDuplicate())
// [1, 2, 3, 4, 5]
  • group() => Groups the array so that the value in the array is the length of the group where you enter the values.
const array = [1, 2, 3, 4, 5, 6];

console.log(array.group(2))
// [[1, 2], [3, 4], [5, 6]]
  • toObject() => Converts the array to an object.
const array = [1, 2, 3, 4, 5];

console.log(array.toObject())
// { 0: 1, 1: 2, 2: 3, 3: 4, 4: 5 }
  • toSet() => Converts the array to a Set Function.
const array = [1, 2, 3, 4, 5, 1, 5, 4, 3, 2];

console.log(array.toSet())
// Set(5) { 1, 2, 3, 4, 5 }

Updates

v0.0.3

  • Updated README.md file.

v0.0.2

  • Added .shuffle(), .swap() and .count() functions.

v0.0.1

  • Module shared publicly 🥳🥳

Please do not forget to use it in the latest version for more stable and performance of the module!

For those who read this far...

  • First of all, thank you so much for reading this far <3

  • Since my English is not very good, I may have made a language mistake in some places, sorry for that, I'm trying to learn more. I hope you can understand what I wrote.

  • If there are mistakes in my module or where you want me to improve, please let me know.

And finally

  • If you want to support this module, if you request me on github, I will be happy to help you.

  • Thank you for reading this far, i love you 💗

  • See you in my next modules!

lovee