0.0.3 • Published 1 year ago

alisa.array v0.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

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