Reusable Accessible Mapping Platform

API Docs for: 5.3.2
Show:

Dictionary Class

A set of useful functions for manipulating dictionaries.

Imports RAMP Modules:

Util

Item Index

Methods

Methods

arrayToMap

(
  • arr
  • fcn
)
Object static

Converts the given array into a dictionary, where the values of the dictionary are values in the array, and the keys are the return value of the given function.

Parameters:

  • arr Object

    an array

  • fcn Function

    a function that takes one argument and returns a key for the given argument

Returns:

Object:

a dictionary

clone

(
  • dict
)
Object static

Returns a shallow copy of the given dictionary.

Parameters:

Returns:

Object:

a shallow copy of the given dictionary

find

(
  • dict
  • fcn
  • [compareFcn]
)
static

Iterates over the key-value pair in the given dictionary and returns the index of the first element to cause the given fcn to return true.

Parameters:

  • dict Object

    a dictionary object

  • fcn Function

    a function that takes the following parameters:

    • the key
    • the value and returns true if the given key or value satisfy some condition
  • [compareFcn] Function optional

    a comparator function (takes two arguments and returns an integer) used to sort the keys

forEachEntry

(
  • dict
  • fcn
  • [sortFcn]
  • [scope]
)
static

Iterates over the key-value pair in the given dictionary (in arbitrary order) and calls the given function on each key-value pair.

Parameters:

  • dict Object

    a dictionary object

  • fcn Function

    a function that takes the following parameters:

    • the key
    • the value
    • obj (an optional parameter) that contains two fields, exit and returnVal. If exit is set to true, forEachEntry terminates right away (without iterating over the rest of the dictionary). The return value of forEackKeyValuePair is returnVal (which by default is undefined).
  • [sortFcn] Function optional

    true if the dictionary keys are to be sorted before iterating

  • [scope] Object optional

    The scope to be hitched to the given fcn

isEmpty

(
  • dict
)
Boolean static

Returns true if the given dictionary is empty (i.e. has no keys)

Parameters:

Returns:

Boolean:

true if the dictionary is empty, false otherwise

length

(
  • dict
)
Integer static

Returns the number of keys in the given dictionary.

Parameters:

Returns:

Integer:

the number of keys in the dictionary

zip

(
  • arr1
  • arr2
)
Object static

Convert the given array into a dictionary, where the keys of the dictionary are the elements in the first array and the values of the dictionary are elements in the second array. The size of the two arrays must match.

Parameters:

Returns:

Object:

a dictionary