@svizzle/utils/array-object

Methods

(static) keyValueArrayToObject(objects) → {object}

Source:
Since:
  • 0.3.0

Return an object built using 'key's and 'value's from the objects in the provided array

Example
> objects = [
	{key: 'ITA', value: 0},
	{key: 'FRA', value: 0},
	{key: 'BRA', value: 0},
	{key: 'GER', value: 1},
	{key: 'USA', value: 1},
]
> keyValueArrayToObject(objects)
{
	'ITA': 0,
	'FRA': 0,
	'BRA': 0,
	'GER': 1,
	'USA': 1
}
Parameters:
Name Type Description
objects array

array of objects

Returns:

object

Type
object

(static) makeAllOccurrences(objects) → {object}

Source:
Since:
  • 0.1.0

Return an object of occurrences of all the keys contained in the objects in the provided array

Example
> objects = [{a: 1}, {a: 6, b: -1}, {a: 2, b: 0, c: 1}, {c: 4, e: 2}]
> makeAllOccurrences(objects)
{a: 3, b: 2, c: 2, e: 1}
Parameters:
Name Type Description
objects array

array of objects

Returns:

occurrences - occurrences of keys

Type
object

(static) makeIndexByKey(array) → {object}

Source:
Since:
  • 0.12.0

Return an object with the provided array elements as keys and all values equal to their index in the array

Example
> makeIndexByKey(['a', 'b'])
{a: 0, b: 1}
> makeIndexByKey([2, -4])
{'2': 0, '-4': 1}
> makeIndexByKey([[1,2,3], [3,4,5], [1,2,3]])
{'3,4,5': 1, '1,2,3': 2}
> makeIndexByKey([[1,2,{a:1}], [3,4,5], [1,2,3]])
{'1,2,[object Object]': 0, '3,4,5': 1, '1,2,3': 2}
> makeIndexByKey([{a: 1}, {b: 2}, {c: 3}])
{'[object Object]': 2}
Parameters:
Name Type Description
array array
Returns:
Type
object

(static) makeKeyedFalse(array) → {object}

Source:
Since:
  • 0.9.0

Return an object with the provided array elements as keys and all values equal to true

Example
> makeKeyedFalse(['a', 'b'])
{a: false, b: false}
Parameters:
Name Type Description
array array
Returns:
Type
object

(static) makeKeyedTrue(array) → {object}

Source:
Since:
  • 0.9.0

Return an object with the provided array elements as keys and all values equal to false

Example
> makeKeyedTrue(['a', 'b'])
{a: true, b: true}
Parameters:
Name Type Description
array array
Returns:
  • keyed trues
Type
object

(static) makeKeyedZeroes(array) → {object}

Source:
Since:
  • 0.1.0

Return an object with the provided array elements as keys and all values equal to zero

Example
> makeKeyedZeroes([1, 2])
{1: 0, 2: 0}
> makeKeyedZeroes(['a', 'b'])
{a: 0, b: 0}
Parameters:
Name Type Description
array array
Returns:
  • keyed zeroes
Type
object

(static) makeOccurrences(objects, keys) → {object}

Source:
Since:
  • 0.1.0

Return an object of occurrences of keys in the provided array containing the provided keys

Example
> objects = [{a: 1}, {a: 6, b: -1}, {a: 2, b: 0, c: 1}, {c: 4, e: 2}]
> makeOccurrences(objects, ['a', 'b'])
{a: 3, b: 2}
> makeOccurrences(objects, ['c', 'e'])
{c: 2, e: 1}
> makeOccurrences(objects, ['k', 'a'])
{k: 0, a: 3}
Parameters:
Name Type Description
objects array

array of objects

keys array

array of keys

Returns:

occurrences - occurrences of keys

Type
object

(static) mergeObjects(objects) → {object}

Source:
Since:
  • 0.5.0

Merge all the objects in the provided array. The result depends on the order of the objects in the array.

Example
> mergeObjects([{a: 1}, {a: 6, b: -1}, {b: 1}])
{a: 6, b: 1}
> mergeObjects([{b: 1}, {a: 6, b: -1}, {a: 1}])
{a: 1, b: -1}
Parameters:
Name Type Description
objects array

array of objects

Returns:
  • merged objects
Type
object