How to understand curry and function composition using Lodash flow?

Silver Spoon Evaluation We’ll just start with tracing the evaluation of addSquare(3, 1) // … Ok, here goes = flow([add, trace(‘after add’), square]) (3, 1) add(3,1) 4 trace(‘after add’) (4) tap(x => console.log(`== ${ ‘after add’ }: ${ x }`)) (4) curry((interceptor, n) => { interceptor(n); return n; }) (x => console.log(`== ${ ‘after add’ … Read more

Filtering object properties based on value

Here are two vanilla javascript options: A.: Iterate over the object’s keys and delete those having a falsey value. var obj = { propA: true, propB: true, propC: false, propD: true, }; Object.keys(obj).forEach(key => { if (!obj[key]) delete obj[key]; }); console.log(obj); See Object.keys() and Array.prototype.forEach() B.: Iterate over the object’s keys and add truthy values … Read more

What happened to Lodash _.pluck?

Ah-ha! The Lodash Changelog says it all… “Removed _.pluck in favor of _.map with iteratee shorthand” var objects = [{ ‘a’: 1 }, { ‘a’: 2 }]; // in 3.10.1 _.pluck(objects, ‘a’); // → [1, 2] _.map(objects, ‘a’); // → [1, 2] // in 4.0.0 _.map(objects, ‘a’); // → [1, 2]

Filter array of objects whose any properties contains a value

You could filter it and search just for one occurence of the search string. Methods used: Array#filter, just for filtering an array with conditions, Object.keys for getting all property names of the object, Array#some for iterating the keys and exit loop if found, String#toLowerCase for getting comparable values, String#includes for checking two string, if one … Read more

How to filter keys of an object with lodash?

Lodash has a _.pickBy function which does exactly what you’re looking for. var thing = { “a”: 123, “b”: 456, “abc”: 6789 }; var result = _.pickBy(thing, function(value, key) { return _.startsWith(key, “a”); }); console.log(result.abc) // 6789 console.log(result.b) // undefined <script src=”https://cdn.jsdelivr.net/lodash/4.16.4/lodash.min.js”></script>

How to make lodash work with Angular JS?

I prefer to introduce ‘_’ globally and injectable for tests, see my answer to this question Use underscore inside controllers var myapp = angular.module(‘myApp’, []) // allow DI for use in controllers, unit tests .constant(‘_’, window._) // use in views, ng-repeat=”x in _.range(3)” .run(function ($rootScope) { $rootScope._ = window._; });