HTML Preparation code:
AخA
 
1
<script src="https://raw.githubusercontent.com/lodash/lodash/4.17.15-npm/core.js"></script>
Tests:
  • WIth loop321321

    x
     
    var mapping = {
      'apple': 5,
      'orange': 10
    };
    var fruits = ['apple', 'orange'];
    const keys = Object.keys(mapping);
    const rows = fruits.map((row) => {
      const transformed = {};
      for (const key of keys) {
        transformed[key] = mapping[key];
      }
      return transformed;
    });
                                     
    console.log(rows);
  • With reduce23132

     
    var mapping = {
      'apple': 5,
      'orange': 10
    };
    var fruits = ['apple', 'orange'];
    var keys = Object.keys(mapping);
    var rows = fruits.map((row) => {
      const transformed = {};
      for (var key of keys) {
        transformed[key] = mapping[key];
      }
      return transformed;
    });
                                   
    var rows = fruits.map((row) =>
        Object.entries(mapping).reduce((acc, [key, transform]) => {
          acc[key] = transform;
          return acc;
        }, {}),
    );
                                     
    console.log(rows);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    WIth loop321321
    With reduce23132

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
Chrome 95 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
WIth loop321321 67084.8 Ops/sec
With reduce23132 66127.5 Ops/sec