utils.array
namespace array
a collection of array utility functions
Summary
Public Methods
random(arr: Array<number | string | Object>) → {any}
return a random array element
// Select a random array element
let arr = [ "foo", "bar", "baz" ];
console.log(me.utils.array.random(arr));
Name | Type | Description |
---|---|---|
arr | Array<number | string | Object> |
array to pick a element |
Type | Description |
---|---|
any |
random member of array |
remove(arr: Array<number | string | Object>, obj: object) → {Array<number | string | Object>}
Remove the specified object from the given Array
Name | Type | Description |
---|---|---|
arr | Array<number | string | Object> |
array from which to remove an object |
obj | object |
to be removed |
Type | Description |
---|---|
Array<number | string | Object> |
the modified Array let arr = [ "foo", "bar", "baz" ]; // remove "foo" from the array me.utils.array.remove(arr, "foo"); |
weightedRandom(arr: Array<number | string | Object>) → {any}
return a weighted random array element, favoring the earlier entries
Name | Type | Description |
---|---|---|
arr | Array<number | string | Object> |
array to pick a element |
Type | Description |
---|---|
any |
random member of array |