Skip to content

Instantly share code, notes, and snippets.

@veteran29
Last active May 10, 2024 00:34
Show Gist options
  • Save veteran29/5d50c975c8f6d0df9208dad68de3deb4 to your computer and use it in GitHub Desktop.
Save veteran29/5d50c975c8f6d0df9208dad68de3deb4 to your computer and use it in GitHub Desktop.
ES2015 Snippets
const createRange = (start, amount) =>
Array.from(Array(amount), (_, idx) => start + idx);
/**
* @param {array} array
*/
const uniqueArray = array => [...new Set(array)];
/**
* @param {array} array
* @param {string} key Should not repeat in array or only last one will be in resulting object
*/
const arrayToObject = (array, groupKey) =>
Object.assign({}, ...array.map(item => ({ [item[groupKey]]: item })));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment