Skip to content

Instantly share code, notes, and snippets.

@Rebolon
Last active October 19, 2017 14:51
Show Gist options
  • Save Rebolon/ba61f48d8172fcac97e77ad8bce6d15d to your computer and use it in GitHub Desktop.
Save Rebolon/ba61f48d8172fcac97e77ad8bce6d15d to your computer and use it in GitHub Desktop.
replace some feature from lodash/underscore with pure es6
let monObjet = {name: "moi", job: "dev", city: "lyon"}
let monTableau = [1, "dessert", "soir", ]
ee = _.first(monTableau)
become
[ee] = monTableau
ee = _.last(monTableau)
become
[ee] = [...monTableau].reverse() // prevent monTableau mutation
ee = _.pick(monObjet, [prop1, prop2])
become
ee = ((monObjet) => {let {job} = monObjet; return {job}})(monObjet)
or this shorter version
ee = (({job}) => ({job}))(monObjet)
and this one with assign
ee = {}; Object.assign(ee, (({job}) => ({job}))(monObjet))
ee = _.omit(monObject, job, name)
become
ee = (({job, name, ...tails}) => (tails))(monObjet)
bool = _.contains(monArray, keyToFind)
become
bool = monArray.find(qryParam => qryParam === keyToFind)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment