adrien-dufond / manmaru.arrayutil

util js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MANMARU ARRAYUTIL JS

Inspired from CASA Lib / AS 2.0 (v.10/06/08) - Aaron Clinger, David Nelson

manmaru.arrayutil.js :
Javascript utilities for sorting, searching and manipulating Arrays.

equals(first, second) ->
Determines if two Arrays contain the same objects at the same index
@param first: First Array to compare to the {@code second}
@param second: Second Array to compare to the {@code first}
@return Returns {@code true} if Arrays are the same; otherwise {@code false}

addItemsAt(tarArray, items, index) ->
Modifies original Array by adding all the elements from another Array at a specified position
@param tarArray: Array to add elements to
@param items: Array of elements to add
@param index: Position where the elements should be added
@return Returns {@code true} if the Array was changed as a result of the call; otherwise {@code false}

removeDuplicates(inArray) ->
Creates new Array composed of only the non-identical elements of passed Array
@param inArray: Array to remove equivalent items
@return A new Array composed of only unique elements

removeItem(tarArray, item) ->
Modifies original Array by removing all items that are identical to the specified item
@param tarArray: Array to remove passed {@code item}
@param item: Element to remove
@return The amount of removed elements that matched {@code item}, if none found returns {@code 0}

removeItems(tarArray, items) ->
Removes only the specified items in an Array
@param tarArray: Array to remove specified items from
@param items: Array of elements to remove
@return Returns {@code true} if the Array was changed as a result of the call; otherwise {@code false}

retainItems(tarArray, items) ->
Retains only the specified items in an Array
@param tarArray: Array to remove non specified items from
@param items: Array of elements to keep
@return Returns {@code true} if the Array was changed as a result of the call; otherwise {@code false}

contains(inArray, item) ->
Finds out how many instances of {@code item} Array contains
@param inArray: Array to search for {@code item} in
@param item: Object to find
@return The amount of {@code item}'s found; if none were found returns {@code 0}

containsAny(inArray, items) ->
Determines if Array {@code inArray} contains any element of Array {@code items}
@param inArray: Array to search for {@code items} in
@param items: Array of elements to search for
@return Returns {@code true} if {@code inArray} contains any element of {@code items}; otherwise {@code false}

getIndexOfDifference(first, second, fromIndex) ->
Compares two Arrays and finds the first index where they differ
@param first: First Array to compare to the {@code second}
@param second: Second Array to compare to the {@code first}
@param fromIndex: The location in the Arrays from which to start searching for a difference
@return The first position/index where the Arrays differ; if Arrays are identical returns {@code -1}

randomize(inArray) ->
Creates new Array composed of passed Array's items in a random order
@param inArray: Array to create copy of, and randomize
@return A new Array composed of passed Array's items in a random order

getLowestValue(inArray) ->
Finds the lowest value in {@code inArray}
@param inArray: Array composed only of numbers
@return The lowest value in {@code inArray}

getHighestValue(inArray) ->
Finds the highest value in {@code inArray}
@param inArray: Array composed only of numbers
@return The highest value in {@code inArray}


How to use:
ArrayUtil.functionName("param");

Example of use :
var testArray = new Array("blue","blue","green","red");
console.log(ArrayUtil.contains(testArray,"blue"));
return -> 2

About

util js


Languages

Language:JavaScript 100.0%