Skip to content

Instantly share code, notes, and snippets.

@sharmaabhinav
Last active November 9, 2017 08:33
Show Gist options
  • Save sharmaabhinav/c0c93025c59ab501dbc97f907f722179 to your computer and use it in GitHub Desktop.
Save sharmaabhinav/c0c93025c59ab501dbc97f907f722179 to your computer and use it in GitHub Desktop.
var _ = {pick}
function pick (object, identifierStr) {
var path = identifierStr.split('.')
if (path.length === 1 ) {
return object[path[0]]
}
var [first, ...rest] = path
return pick(object[first], rest.join('.'))
}
const flatten = (arr) => arr.reduce((acc, val) => acc.concat(val), [])
function keys (object, path) {
var object_keys = []
for (var key of Object.keys(object)) {
object_keys = object_keys.concat([`${path}.${key}`])
if (typeof object[key] === 'object') {
object_keys = object_keys.concat(keys(object[key], `${path}.${key}`))
}
}
return object_keys
}
function mixin( sourceObj, targetObj ) {
for (var key in sourceObj) {
targetObj[key] = sourceObj[key];
}
return targetObj;
}
function isNull (val){
return !val && typeof val === 'object'
}
// pollyfill for isNaN
if (!Number.isNaN) {
Number.isNaN = function(n) {
return (
typeof n === "number" &&
window.isNaN( n )
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment