Kristofer Giltvedt Selbekk
I'm a full stack engineer that just happens to love React, CSS and front end in general
lodash
var largestValueInObject = function(object) {
if (!_.isObject(object)) {
throw new Error('Objects only pls.');
}
var values = _.values(object);
return _.max(values);
}Object.assign
Object.entries
Number.isNaN
Array.from
{...spread}
f => f
@Decorators
let variable;
_.isObject(obj) // Nope
typeof(obj) === 'object' // Yup
_.isArray(arr) // Nope
Array.isArray(arr) // Yup
_.spread(func, [1, 2, 3]) // Nope
func(...[1, 2, 3]) // Yup
_.isNaN(nan) // Nope
Number.isNaN(nan) // Yup
// Here, take a cantaNOPE
var mapped = _.map(array, function(item) {
return item.someKey;
});
// Much better
var map = array.map(item => item.someKey);var consultant = {
name: 'Kristofer',
age: 29,
project: 'SpareBank 1',
};
// Njet
var nameAndAge = _.omit(consultant, 'project');
// SI BUENO
const { project, ...nameAndAge } = consultant;var colors = ['blue', 'green', 'yellow', 'rainbow'];
// NOPE DIEM
var blue = _.first(colors);
var restOfColors = _.rest(colors);
// OUI OUI OUI
const [blue, ...restOfColors] = colors;// kthxnope
var sayHello = function(nameAndGreeting) {
var defaultArgs = { greeting: 'howdy', name: 'partner' };
var args = {};
_.defaults(args, nameAndGreeting, defaultArgs);
alert(args.greeting + ' ' + args.name + '!');
}
// like, totally!
const sayHello = ({ greeting = 'howdy', name: 'partner' }) => {
alert(`${greeting} ${name}!`)
}var numbers = [1, 2, 3, 4, 5];
// nope-a-thon
var maxValueOfArray = _.max(numbers);
// so smooth
const sayHello = Math.max(...numbers);const values = [0, 1, false, 2, '', 3];
// I nope think so
var onlyTruthyValues = _.compact(values);
// yup please
const onlyTruthyValues = values.filter(v => v);debounce
throttle
curry
Date.now();function func() {}
func.bind(this);value >= othervalue === nullone + twoone + twoBy Kristofer Giltvedt Selbekk
I'm a full stack engineer that just happens to love React, CSS and front end in general