Skip to content

Instantly share code, notes, and snippets.

@jongacnik
Last active October 25, 2016 19:33
Show Gist options
  • Save jongacnik/a25a6e916edc134d32ee991c4a622fa6 to your computer and use it in GitHub Desktop.
Save jongacnik/a25a6e916edc134d32ee991c4a622fa6 to your computer and use it in GitHub Desktop.
Good Ones

Good Ones

Array Diff

const difference = (a1, a2) => a1.filter(x => a2.indexOf(x) == -1)

Source

Populate Array

Creates array with 1...N elements

[...Array(10).keys()]
//→ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Source

NodeList to Array

[...document.querySelectorAll('div')]

Source

Merge

const merge = (...xs) => Object.assign({}, ...xs)

Source

Limit

const limit = (value, min, max) => Math.min(Math.max(value, min), max)

Map Object

const x = require('xtend')

const mapObject = (obj, cb) => {
  return x(...Object.keys(obj).map(k => {
    const newObj = {}
    newObj[k] = cb(obj[k])
    return newObj
  }))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment