time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

repl.txt (1412B)


      1 
      2 {{alias}}( obj[, options] )
      3     Inverts an object, such that keys become values and values become keys.
      4 
      5     Beware when providing objects having values which are themselves objects.
      6     The function relies on native object serialization (`#toString`) when
      7     converting values to keys.
      8 
      9     Insertion order is not guaranteed, as object key enumeration is not
     10     specified according to the ECMAScript specification. In practice, however,
     11     most engines use insertion order to sort an object's keys, thus allowing for
     12     deterministic inversion.
     13 
     14     Parameters
     15     ----------
     16     obj: ObjectLike
     17         Input object.
     18 
     19     options: Object (optional)
     20         Options.
     21 
     22     options.duplicates: boolean (optional)
     23         Boolean indicating whether to store keys mapped to duplicate values in
     24         arrays. Default: `true`.
     25 
     26     Returns
     27     -------
     28     out: Object
     29         Inverted object.
     30 
     31     Examples
     32     --------
     33     // Basic usage:
     34     > var obj = { 'a': 'beep', 'b': 'boop' };
     35     > var out = {{alias}}( obj )
     36     { 'beep': 'a', 'boop': 'b' }
     37 
     38     // Duplicate values:
     39     > obj = { 'a': 'beep', 'b': 'beep' };
     40     > out = {{alias}}( obj )
     41     { 'beep': [ 'a', 'b' ] }
     42 
     43     // Override duplicate values:
     44     > obj = {};
     45     > obj.a = 'beep';
     46     > obj.b = 'boop';
     47     > obj.c = 'beep';
     48     > out = {{alias}}( obj, { 'duplicates': false } )
     49     { 'beep': 'c', 'boop': 'b' }
     50 
     51     See Also
     52     --------
     53