Travis build: 1951
This commit is contained in:
@ -17,14 +17,16 @@ const hz = (fn, iterations = 100) => {
|
||||
|
||||
```js
|
||||
// 10,000 element array
|
||||
const numbers = Array(10000).fill().map((_, i) => i);
|
||||
const numbers = Array(10000)
|
||||
.fill()
|
||||
.map((_, i) => i);
|
||||
|
||||
// Test functions with the same goal: sum up the elements in the array
|
||||
const sumReduce = () => numbers.reduce((acc, n) => acc + n, 0);
|
||||
const sumForLoop = () => {
|
||||
let sum = 0
|
||||
for (let i = 0; i < numbers.length; i++) sum += numbers[i]
|
||||
return sum
|
||||
let sum = 0;
|
||||
for (let i = 0; i < numbers.length; i++) sum += numbers[i];
|
||||
return sum;
|
||||
};
|
||||
|
||||
// `sumForLoop` is nearly 10 times faster
|
||||
|
||||
@ -5,12 +5,14 @@ Replaces the names of multiple object keys with the values provided.
|
||||
Use `Object.keys()` in combination with `Array.reduce()` and the spread operator (`...`) to get the object's keys and rename them according to `keysMap`.
|
||||
|
||||
```js
|
||||
const renameKeys = (keysMap, obj) => Object
|
||||
.keys(obj)
|
||||
.reduce((acc, key) => ({
|
||||
...acc,
|
||||
...{ [keysMap[key] || key]: obj[key] }
|
||||
}), {});
|
||||
const renameKeys = (keysMap, obj) =>
|
||||
Object.keys(obj).reduce(
|
||||
(acc, key) => ({
|
||||
...acc,
|
||||
...{ [keysMap[key] || key]: obj[key] }
|
||||
}),
|
||||
{}
|
||||
);
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
Reference in New Issue
Block a user