arraylist

0.1.0 • Public • Published

ArrayList

ArrayList inherits from JavaScript Array, without overwriting or populate this class.

Install:

# npm install arraylist

API:

  • get(index)

    Returns an element by position:

var list = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list.get(0); // 1
list.get(1); // 2
list.get(0) == list[0]; // true
  • set(index, value)

    Set an element by position

var list = new ArrayList;
list.set(0, 'hello');
list.set(1, 'world');
list.get(0); // hello
list.get(1); // world
  • contains(element)

    Check if an element is in the list

var list = new ArrayList;
list.add([1, 2, 3]);
list.contains(1)); // true
list.contains(2)); // true
list.contains(3)); // true
list.contains(4)); // false
  • add(elements)

    Add elements to the list

var list = new ArrayList;
list.add(1);
list.add('car');
list.add([2, 3, 4]);
list.length; // 5
  • isEmpty()

    Check if the list contains no elements

var list = new ArrayList;
list.isEmpty(); // true
list.add('something');
list.isEmpty(); // false
  • equals(list)

    Check if two lists are equals

var list = new ArrayList;
var list2 = new ArrayList;
list.add([1, 2, 3]);
list.equals(list2); // false
list2.add([1, 2, 3]);
list.equals(list2); // true
  • clone()

    Creates a copy of the list

var list = new ArrayList;
list.add([1, 2, 3]);
var list2 = list.clone();
list.equals(list2); // true
  • remove(index)

    Removes an element by position

var list = new ArrayList;
list.add([1, 2, 3]);
list.remove(0);
list; // [2, 3]
  • removeElement(element)

    Removes a specified element

var list = new ArrayList;
list.add([1, 2, 3]);
list.removeElement(2);
list; // [1, 3]
  • removeAll(list)

    Remove all the elements in another collection

var list = new ArrayList;
var list2 = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list2.add([1, 3, 5]);
list.removeAll(list2);
list; // [2, 4]
  • replaceAll(list)

    Replace all the elements of the list

var list = new ArrayList;
var list2 = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list2.add([1, 3, 5]);
list.replaceAll(list2);
list; // [1, 3, 5]
  • clear()

    Remove all the elements in the list

var list = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list.clear();
list.isEmpty(); // true
  • toArray()

    Return a new array with all the elements in the same order

var list = new ArrayList;
list.add([1, 2, 3]);
list.toArray(); // [1, 2, 3]
  • first([n])

    Returns the first element of the list. [see]

var list = new ArrayList;
list.add([1, 2, 3]);
list.first(); // 1
list.first(2); // [1, 2]
  • initial([n])

    Returns everything but the last entry of the list. [see]

var list = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list.initial(); // [1, 2, 3, 4]
  • last([n])

    Returns the last element of the list. [see]

var list = new ArrayList;
list.add([1, 2, 3]);
list.last(); // 3
  • rest(index)

    Returns the rest of the elements in the list. [see]

var list = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list.rest(); // [1, 2, 3, 4]
  • compact()

    Returns a new list with the false values removed. [see]

var list = new ArrayList;
list.add([1, false, 0, '', 5]);
list.compact(); // [1, 5]
  • flatten()

    Returns a new list flattened. [see]

var list = new ArrayList;
list.add([1, [2], [[3]]]);
list.flatten(); // [1, 2, 3]
  • *without(values)

    Returns a new list without the specified values. [see]

var list = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list.without([1, 3, 5]); // [2, 4]
  • partition(predicate)

    Split the list into two lists. [see]

var list = new ArrayList;
list.add([1, 2, 3, 4]);
list.partition(function(n) {
  return n % 2 == 0; // pair or odd
}); // [[1, 3], [2, 4]]
  • *union(lists)

    Returns the list joined with the arrays specified, the join is unique. [see]

var list = new ArrayList;
var list2 = new ArrayList;
list.add([1, 2, 3]);
list2.add([1, 4, 5]);
list.union(list2); // [1, 2, 3, 4, 5]
  • *intersection(lists)

    Returns the list intercepted with the arrays specified, the intersection is unique. [see]

var list = new ArrayList;
var list2 = new ArrayList;
list.add([1, 2, 3]);
list2.add([1, 2, 4]);
list.intersection(list2); // [1, 2]
  • *difference(lists)

    Returns the list minus the lists specified, the difference is unique. [see]

var list = new ArrayList;
var list2 = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list2.add([1, 3, 5, 10]);
list.difference(list2); // [2, 4]
  • unique()

    Returns a list with the duplicated values removed. [see]

var list = new ArrayList;
list.add([1, 2, 2, 3, 3, 4]);
list.unique(); // [1, 2, 3, 4]
  • uniq()

    Alias for unique.

  • *zip(lists)

    Merges together the values of each of the lists with the values at the corresponding position. [see]

  • object([values])

    Converts lists into objects. [see]

  • sortedIndex(value, [iterator], [context])

    Returns the index at which the value should be inserted into the list. [see]

var list = new ArrayList;
list.add([10, 20, 30]);
list.sortedIndex(25); // 2
  • each()

    Alias for forEach.

  • map(iterator, [context])

    Returns a new list with each value mapped through a transformation. [see]

var list = new ArrayList;
list.add([1, 2, 3]);
list.map(function (n) {
  return n * 2;
}); // [2, 4, 6]
  • reduce(iterator, memo, [context])

    [see]

  • reduceRight(iterator, memo, [context])

    [see]

  • find(predicate, [context])

    Returns a new list with the occurrences that passes the test. [see]

var list = new ArrayList;
list.add([1, 2, 3, 4, 5, 6]);
list.find(function (n) {
  return n % 2 == 0;
}); // [2, 4, 6]
  • findOne(predicate, [context])

    Returns the first occurrence that passes the test. [see]

var list = new ArrayList;
list.add([1, 2, 3, 4, 5, 6]);
list.findOne(function (n) {
  return n % 2 == 0;
}); // 2
  • where(properties)

    [see]

  • findWhere(properties)

    [see]

  • reject(predicate, [context])

    Returns the values in list without the elements that the truth test passes. [see]

  • every([predicate], [context])

    Returns true if all of the values in the list pass the predicate truth test. [see]

var list = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list.every(function (n) {
  return n > 0;
}); // true
  • some([predicate], [context])

    Returns true if any of the values in the list pass the predicate truth test. [see]

var list = new ArrayList;
list.add([1, 2, 3]);
list.some(function (n) {
  return n % 2 == 0;
}); // true
  • *invoke(methodName, arguments)

    Calls the method on each value in the list. [see]

var list = new ArrayList;
list.add([1, 2, 3]);
  • pluck(propertyName)

    [see]

  • max([iterator], [context])

    Returns the maximum value in list. [see]

var list = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list.max(); // 5
  • min([iterator], [context])

    Returns the minimum value in list. [see]

var list = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list.min(); // 1
  • sortBy(iterator, [context])

    Returns a new list with the values sorted. [see]

  • groupBy(iterator, [context])

    [see]

  • indexBy(iterator, [context])

    [see]

  • countBy(iterator, [context])

    [see]

  • shuffle()

    Returns a shuffled copy of the list, using a version of the Fisher-Yates shuffle. [see]

var list = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list.shuffle(); // [3, 1, 5, 4, 2]
  • sample([n])

    Returns a random sample from the list. [see]

var list = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list.sample(); // 4
  • size()

    Returns the length of the list.

var list = new ArrayList;
list.add([1, 2, 3, 4, 5]);
list.size(); // 5

Package Sidebar

Install

npm i arraylist

Weekly Downloads

802

Version

0.1.0

License

MIT

Last publish

Collaborators

  • marianopardo