You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/utils/object-inverse-by/README.md
+19-22Lines changed: 19 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ var invertBy = require( '@stdlib/utils/object-inverse-by' );
32
32
33
33
#### invertBy( obj, \[options,] transform )
34
34
35
-
Inverts an `object`, such that keys become values and values become keys, according to a `transform` function.
35
+
Inverts an object, such that keys become values and values become keys, according to a transform function.
36
36
37
37
```javascript
38
38
functiontransform( key, value ) {
@@ -46,11 +46,11 @@ var out = invertBy( obj, transform );
46
46
// returns { 'beep': 'a', 'boop': 'b' }
47
47
```
48
48
49
-
The function accepts the following `options`:
49
+
The function accepts the following options:
50
50
51
-
-**duplicates**: `boolean` indicating whether to store keys mapped to duplicate values in `arrays`. Default: `true`.
51
+
-**duplicates**: boolean indicating whether to store keys mapped to duplicate values in arrays. Default: `true`.
52
52
53
-
By default, keys mapped to duplicate values are stored in `arrays`.
53
+
By default, keys mapped to duplicate values are stored in arrays.
54
54
55
55
```javascript
56
56
functiontransform( key, value ) {
@@ -64,7 +64,7 @@ var out = invertBy( obj, transform );
64
64
// returns { 'beep': [ 'a', 'b' ] }
65
65
```
66
66
67
-
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`.
67
+
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.
68
68
69
69
```javascript
70
70
functiontransform( key, value ) {
@@ -82,7 +82,7 @@ var out = invertBy( obj, opts, transform );
82
82
// returns { 'beep': 'c', 'boop': 'b' }
83
83
```
84
84
85
-
The `transform` function is provided three arguments:
85
+
The transform function is provided three arguments:
86
86
87
87
-**key**: object key.
88
88
-**value**: object value corresponding to `key`.
@@ -112,7 +112,7 @@ var out = invertBy( obj, transform );
112
112
113
113
## Notes
114
114
115
-
- 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.
115
+
- 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.
116
116
117
117
```javascript
118
118
functiontransform( key, value ) {
@@ -129,7 +129,7 @@ var out = invertBy( obj, transform );
-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.
132
+
-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.
133
133
134
134
</section>
135
135
@@ -142,27 +142,24 @@ var out = invertBy( obj, transform );
142
142
<!-- eslint no-undef: "error" -->
143
143
144
144
```javascript
145
-
var randu = require( '@stdlib/random/base/randu' );
146
-
var round = require( '@stdlib/math/base/special/round' );
145
+
var objectKeys = require( '@stdlib/utils/keys' );
146
+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
147
147
var invertBy = require( '@stdlib/utils/object-inverse-by' );
148
148
149
-
var keys;
150
-
var arr;
151
-
var out;
152
-
var i;
153
-
154
149
function transform( key, value ) {
155
150
return value;
156
151
}
157
152
158
-
// Create an array of random integers...
159
-
arr = new Array( 1000 );
160
-
for ( i = 0; i < arr.length; i++ ) {
161
-
arr[ i ] = round( randu()*100.0 );
162
-
}
153
+
// Create an array of random integers:
154
+
var arr = discreteUniform( 1000, 0, 100, {
155
+
'dtype': 'generic'
156
+
});
157
+
163
158
// Invert the array to determine value frequency...
* - The transform function is provided three arguments:
81
81
*
82
-
* - `key`: object key
83
-
* - `value`: object value corresponding to `key`
84
-
* - `obj`: the input object
82
+
* - `key`: object key.
83
+
* - `value`: object value corresponding to `key`.
84
+
* - `obj`: the input object.
85
85
*
86
86
* - 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.
87
87
*
88
-
* - 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.
88
+
* - 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.
* - The transform function is provided three arguments:
124
124
*
125
-
* - `key`: object key
126
-
* - `value`: object value corresponding to `key`
127
-
* - `obj`: the input object
125
+
* - `key`: object key.
126
+
* - `value`: object value corresponding to `key`.
127
+
* - `obj`: the input object.
128
128
*
129
129
* - 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.
130
130
*
131
-
* - 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.
131
+
* - 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.
0 commit comments