diff --git a/lib/node_modules/@stdlib/utils/object-inverse-by/README.md b/lib/node_modules/@stdlib/utils/object-inverse-by/README.md index 3fd534f6fb2a..8c1651d1a57a 100644 --- a/lib/node_modules/@stdlib/utils/object-inverse-by/README.md +++ b/lib/node_modules/@stdlib/utils/object-inverse-by/README.md @@ -32,7 +32,7 @@ var invertBy = require( '@stdlib/utils/object-inverse-by' ); #### invertBy( obj, \[options,] transform ) -Inverts an `object`, such that keys become values and values become keys, according to a `transform` function. +Inverts an object, such that keys become values and values become keys, according to a transform function. ```javascript function transform( key, value ) { @@ -46,11 +46,11 @@ var out = invertBy( obj, transform ); // returns { 'beep': 'a', 'boop': 'b' } ``` -The function accepts the following `options`: +The function accepts the following options: -- **duplicates**: `boolean` indicating whether to store keys mapped to duplicate values in `arrays`. Default: `true`. +- **duplicates**: boolean indicating whether to store keys mapped to duplicate values in arrays. Default: `true`. -By default, keys mapped to duplicate values are stored in `arrays`. +By default, keys mapped to duplicate values are stored in arrays. ```javascript function transform( key, value ) { @@ -64,7 +64,7 @@ var out = invertBy( obj, transform ); // returns { 'beep': [ 'a', 'b' ] } ``` -To **not** allow duplicates, set the `duplicates` option to `false`. The output `key-value` pair will be the `key` most recently inserted into the input `object`. +To **not** allow duplicates, set the `duplicates` option to `false`. The output key-value pair will be the key most recently inserted into the input object. ```javascript function transform( key, value ) { @@ -82,7 +82,7 @@ var out = invertBy( obj, opts, transform ); // returns { 'beep': 'c', 'boop': 'b' } ``` -The `transform` function is provided three arguments: +The transform function is provided three arguments: - **key**: object key. - **value**: object value corresponding to `key`. @@ -112,7 +112,7 @@ var out = invertBy( obj, transform ); ## Notes -- Beware when providing `objects` having values which are themselves `objects`. This function relies on native `object` serialization (`#toString`) when converting `transform` function return values to keys. +- Beware when providing objects having values which are themselves objects. This function relies on native object serialization (`#toString`) when converting transform function return values to keys. ```javascript function transform( key, value ) { @@ -129,7 +129,7 @@ var out = invertBy( obj, transform ); // returns { '1,2,3': 'a', '[object Object]': 'b' } ``` -- Insertion order is not guaranteed, as `object` key enumeration is not specified according to the [ECMAScript specification][ecma-262-for-in]. In practice, however, most engines use insertion order to sort an `object`'s keys, thus allowing for deterministic inversion. +- In older JavaScript engines, insertion order is not guaranteed, as object key enumeration was not specified according to the [ECMAScript specification][ecma-262-for-in] in earlier editions. In practice, however, most older engines use insertion order to sort an object's keys, thus allowing for deterministic inversion. @@ -142,27 +142,24 @@ var out = invertBy( obj, transform ); ```javascript -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var objectKeys = require( '@stdlib/utils/keys' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var invertBy = require( '@stdlib/utils/object-inverse-by' ); -var keys; -var arr; -var out; -var i; - function transform( key, value ) { return value; } -// Create an array of random integers... -arr = new Array( 1000 ); -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = round( randu()*100.0 ); -} +// Create an array of random integers: +var arr = discreteUniform( 1000, 0, 100, { + 'dtype': 'generic' +}); + // Invert the array to determine value frequency... -out = invertBy( arr, transform ); -keys = Object.keys( out ); +var out = invertBy( arr, transform ); +var keys = objectKeys( out ); + +var i; for ( i = 0; i < keys.length; i++ ) { if ( out[ i ] ) { out[ i ] = out[ i ].length; diff --git a/lib/node_modules/@stdlib/utils/object-inverse-by/docs/repl.txt b/lib/node_modules/@stdlib/utils/object-inverse-by/docs/repl.txt index 2655f215b7ad..0cf84af38505 100644 --- a/lib/node_modules/@stdlib/utils/object-inverse-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/utils/object-inverse-by/docs/repl.txt @@ -15,10 +15,10 @@ serialization (`#toString`) when converting transform function return values to keys. - Insertion order is not guaranteed, as object key enumeration is not - specified according to the ECMAScript specification. In practice, however, - most engines use insertion order to sort an object's keys, thus allowing for - deterministic inversion. + In older JavaScript engines, insertion order is not guaranteed, as object + key enumeration was not specified according to the ECMAScript specification + in earlier editions. In practice, however, most older engines use insertion + order to sort an object's keys, thus allowing for deterministic inversion. Parameters ---------- diff --git a/lib/node_modules/@stdlib/utils/object-inverse-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/utils/object-inverse-by/docs/types/index.d.ts index c78ed046128f..942ca87be454 100644 --- a/lib/node_modules/@stdlib/utils/object-inverse-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/utils/object-inverse-by/docs/types/index.d.ts @@ -79,13 +79,13 @@ type Transform = Nullary | Unary | Binary | Ternary; * * - The transform function is provided three arguments: * -* - `key`: object key -* - `value`: object value corresponding to `key` -* - `obj`: the input object +* - `key`: object key. +* - `value`: object value corresponding to `key`. +* - `obj`: the input object. * * - The value returned by a transform function should be a value which can be serialized as an object key. Hence, beware when providing objects having values which are themselves objects. The function relies on native object serialization (`#toString`) when converting transform function return values to keys. * -* - Insertion order is not guaranteed, as object key enumeration is not specified according to the ECMAScript specification. In practice, however, most engines use insertion order to sort an object's keys, thus allowing for deterministic inversion. +* - In older JavaScript engines, insertion order is not guaranteed, as object key enumeration was not specified according to the ECMAScript specification in earlier editions. In practice, however, most older engines use insertion order to sort an object's keys, thus allowing for deterministic inversion. * * @param obj - input object * @param transform - transform function @@ -122,13 +122,13 @@ declare function invertBy( obj: any, transform: Transform ): any; * * - The transform function is provided three arguments: * -* - `key`: object key -* - `value`: object value corresponding to `key` -* - `obj`: the input object +* - `key`: object key. +* - `value`: object value corresponding to `key`. +* - `obj`: the input object. * * - The value returned by a transform function should be a value which can be serialized as an object key. Hence, beware when providing objects having values which are themselves objects. The function relies on native object serialization (`#toString`) when converting transform function return values to keys. * -* - Insertion order is not guaranteed, as object key enumeration is not specified according to the ECMAScript specification. In practice, however, most engines use insertion order to sort an object's keys, thus allowing for deterministic inversion. +* - In older JavaScript engines, insertion order is not guaranteed, as object key enumeration was not specified according to the ECMAScript specification in earlier editions. In practice, however, most older engines use insertion order to sort an object's keys, thus allowing for deterministic inversion. * * @param obj - input object * @param opts - function options diff --git a/lib/node_modules/@stdlib/utils/object-inverse-by/examples/index.js b/lib/node_modules/@stdlib/utils/object-inverse-by/examples/index.js index 1b4b40b2b0b3..b71ddc803884 100644 --- a/lib/node_modules/@stdlib/utils/object-inverse-by/examples/index.js +++ b/lib/node_modules/@stdlib/utils/object-inverse-by/examples/index.js @@ -19,27 +19,23 @@ 'use strict'; var objectKeys = require( '@stdlib/utils/keys' ); -var randu = require( '@stdlib/random/base/randu' ); -var round = require( '@stdlib/math/base/special/round' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var invertBy = require( './../lib' ); -var keys; -var arr; -var out; -var i; - function transform( key, value ) { return value; } -// Create an array of random integers... -arr = new Array( 1000 ); -for ( i = 0; i < arr.length; i++ ) { - arr[ i ] = round( randu()*100.0 ); -} +// Create an array of random integers: +var arr = discreteUniform( 1000, 0, 100, { + 'dtype': 'generic' +}); + // Invert the array to determine value frequency... -out = invertBy( arr, transform ); -keys = objectKeys( out ); +var out = invertBy( arr, transform ); +var keys = objectKeys( out ); + +var i; for ( i = 0; i < keys.length; i++ ) { if ( out[ i ] ) { out[ i ] = out[ i ].length;