The Wayback Machine - http://web.archive.org/web/20201225175731/https://github.com/wutility/array-xtra
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Readme.md

💨[Xtra]

Extra array methods : rand, uniq, sum, contain, flatt
badgen badgen

$ npm i array-xtra --save

Usage

import {uniq} from 'array-xtra'
// or
var {uniq} = require('array-xtra')

Or include it via jsDelivr CDN:

<script src="https://cdn.jsdelivr.net/npm/array-xtra@0.1.3/build/index.min.js"></script>
// access via object : xtra 
xtra.uniq([1, 2, 3, 1, 2]) // [1,2,3]

Methods & Examples

  • remove([], element, [startIndex]) : []
remove([1,2,3,1], 1) // [2, 3, 1]
remove(['a','b','c','a'], 'a') // ['b', 'c', 'a']
  • removeAll([], element, [startIndex]) : []
removeAll([1,2,3,1], 1) // [2, 3]
removeAll(['a','b','c','a'], 'a') // ['b', 'c']
  • rand([]) : Number|String
    return random item from an Array
rand([1, 2, 3]) // 3
rand(['a','b','c']) // 'c'
  • uniq([]) : []
uniq([1, 2, 3, 1, 2]) // [1, 2, 3]
  • sum([], [startIndex]) : Number
sum([1, 2, 3]) // 6
sum([1, 2, 3], 2) // 3
  • contain([], element, [startIndex]) : Boolean
contain([1, 2, 3, 1, 2], 2) // true
contain([1, 2, 3], 2, 2) // false
  • flatt([]) : []
flatt([1, 2, [3, [4]]]) // [ 1, 2, 3, 4 ]

Notes

  • Works both in Node.js and in the browser.
  • Supported in all old and modern browsers.
  • All pull requests are welcome, feel free.

License

MIT

About

💨Array extra methods : uniq, sum, contain, flatt

Topics

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.