Dictionary Class
A set of useful functions for manipulating dictionaries.
Item Index
Methods
- _wrapFileCallInPromise
- arrayToMap static
- clone static
- find static
- forEachEntry static
- isEmpty static
- length static
- zip static
Methods
_wrapFileCallInPromise
-
readMethod
Helper function for wrapping File API calls in Promise objects. Used for building a series of helpers which call different file read methods.
Parameters:
-
readMethod
Stringa string indicating the FileReader method to call
Returns:
a function which accepts a {File} object and returns a Promise
arrayToMap
-
arr
-
fcn
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:
Returns:
a dictionary
clone
-
dict
Returns a shallow copy of the given dictionary.
Parameters:
-
dict
Objecta dictionary
Returns:
a shallow copy of the given dictionary
find
-
dict
-
fcn
-
[compareFcn]
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:
forEachEntry
-
dict
-
fcn
-
[sortFcn]
-
[scope]
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
Objecta dictionary object
-
fcn
Functiona 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).
- the
-
[sortFcn]
Function optionaltrue if the dictionary keys are to be sorted before iterating
-
[scope]
Object optionalThe scope to be hitched to the given fcn
isEmpty
-
dict
Returns true if the given dictionary is empty (i.e. has no keys)
Parameters:
-
dict
Objecta dictionary
Returns:
true if the dictionary is empty, false otherwise
length
-
dict
Returns the number of keys in the given dictionary.
Parameters:
-
dict
Objecta dictionary
Returns:
the number of keys in the dictionary