Skip to content

Instantly share code, notes, and snippets.

View annygutierrez's full-sized avatar
:electron:
Learning new things

Anny Gutierrez Lopez annygutierrez

:electron:
Learning new things
View GitHub Profile
@annygutierrez
annygutierrez / refactor-algorithm.js
Created September 10, 2020 04:58
How to improve the performance of an algorithm by indexing an array
let users = [];
let products = [];
const keyBy = (arr, key) => arr.reduce((acc,el) => {
acc[el[key]] = el;
return acc;
}, {});
const elem = 50000;
for (let i = 0; i < elem; i++) {