Reusable Accessible Mapping Platform

API Docs for: 5.2.0
Show:

Array Class

Set of functions that deal with arrays.

Imports RAMP Modules:

Util

Item Index

Methods

Methods

binaryFind

(
  • arr
  • compareFcn
)
Number static

Given a function which takes one argument and returns 1, 0, or -1, returns the first element which causes the given function to return 0.

Parameters:

Returns:

Number:

the index of the element that causes the given function to return 0, returns -1 if no such element exists

binaryIndexOf

(
  • arr
  • compareFcn
)
Number static

Given a function which takes one argument and returns 1, 0, or -1, returns the first element which causes the given function to return 0.

Parameters:

Returns:

Number:

the index of the element that causes the given function to return 0, returns -1 if no such element exists

find

(
  • arr
  • predicate
  • scope
)
Object static

Returns the first element in the given array that satisfies the given predicate. Returns null if no element in the given array satisfies the given predicate.

EXAMPLE
var array = [1, 2, 3, 4]
find(array, function(a_number) { return a_number === 2 }); -> 2
find(array, function(a_number) { return a_number === 5 }); -> null

Parameters:

  • arr Array

    Array to be searched

  • predicate Function

    a function that takes two arguments (element and its index) and returns true if the argument satisfies some condition, and false otherwise.

  • scope Object

    ???

Returns:

Object:

first element that satisfies the given predicate; null if no such element is found

indexOf

(
  • arr
  • predicate
  • scope
)
Number static

Returns the index of the first element in the given array that satisfies the given predicate. Returns -1 if no element in the given array satisfies the predicate.

Parameters:

  • arr Array

    Array to be searched

  • predicate Function

    a function that takes two arguments (element and its index) and returns true if the argument satisfies some condition, and false otherwise.

  • scope Object

    ???

Returns:

Number:

index of the first element that satisfied the predicate; -1 if no such element is found

remove

(
  • array
  • obj
  • [predicate]
)
static

Removes an item from the specified array.

Parameters:

  • array Array

    Array to have the item removed from

  • obj Number | String | Object

    can be either an index of the item to be removed, a String to be removed from the array of strings, or an actual Object to be removed; if obj is an Object, you need to provide a predicate function

  • [predicate] Function optional

    a function that takes one argument and returns true if the argument satisfies some condition, and false otherwise.

unique

(
  • array
)
Array static

Returns an array that has only unique values (only the first element is kept).

Parameters:

  • array Array

    Array to be searched

Returns:

Array:

array that has only unique values