Travis build: 1951

This commit is contained in:
30secondsofcode
2018-04-12 18:45:32 +00:00
parent 823dbdd8df
commit 07fc5cd355
14 changed files with 132 additions and 21 deletions

View File

@ -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

View File

@ -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