array-extra-methods

1.0.6 • Public • Published

Node.js Array Extra methods

Those are some extra methods for the Array prototype in nodejs. I will add to it any methods that I find useful, but that are not implemented by default.

Installing

npm install array-extra-methods

Implemented methods

  • Array.prototype.sample = function()

    • Returns a random element from the array
  • Array.prototype.take = function()

    • Returns a random element from the array and removes the element from it
  • Array.prototype.last = function()

    • Returns the last element from the array
  • Array.prototype.shuffle = function()

    • Shuffles the values of the array
  • Array.prototype.shuffled = function()

    • Returns a copy of the array with shuffled elements
  • Array.prototype.swap = function(ind1, ind2)

    • Swaps both values of an array
  • Array.prototype.high = function()

    • Returns the last index of the array
  • Array.prototype.group = function(amount)

    • Divides the array into "amount" groups, don't change the array
  • Array.prototype.groupLen = function(amount)

    • Divides the array into groups of 'len' length, don't change the array

Author

Ícaro Augusto

Changelogs

1.0.2

groupLen method added

1.0.1

group method added

1.0.0

Created.

Package Sidebar

Install

npm i array-extra-methods

Weekly Downloads

7

Version

1.0.6

License

ISC

Unpacked Size

3.83 kB

Total Files

3

Last publish

Collaborators

  • icaroaugusto