Skip to main content
15 votes
Accepted

lodash filter array of objects by array of exclude property values

You can do it with filter: ...
Muhammad Faizan's user avatar
7 votes

Generating an array of unique values of a specific property in an object array

I know this is an old post but purely for those looking for ways to do this heres a way that I found works nicely with a single line ...
Ibsy's user avatar
  • 71
7 votes

Convert object array to hash map using lodash

Since lodash 4, you can use _.fromPairs: ...
Ricardo Stuven's user avatar
6 votes
Accepted

JavaScript function to convert an array to an array of strings (formatted)

First impressions: too much nesting, too many nested returns inconsistent style, inconsistent naming You already recognized the potential for refactoring. The simplest possible technique for ...
le_m's user avatar
  • 1,925
4 votes

Checking if any competitors have a non-empty name

Since ES5 (which all browsers support nowadays) is array.some(). It works in the same way as Lodash's/Underscore's _.some() but ...
Joseph's user avatar
  • 25.1k
3 votes

Counting duration values

It's not really clear what you mean by "functional". The use of reduce is nifty, and correctly done, but it seem like cargo cult programming. The realization that ...
ShapeOfMatter's user avatar
3 votes
Accepted

Mean by properties in array of objects

Since this is labelled TypeScript, I'm going to review it as such. First of all, you aren't using types, which defeats the purpose of using TypeScript. You should define what your objects look like <...
VLAZ's user avatar
  • 455
3 votes
Accepted

Get an object with null values from an array of nested objects

Performance. map and flatMap create copies of the arrays. For each new item added to the result you rebuild the whole results ...
Blindman67's user avatar
  • 22.1k
3 votes
Accepted

Transforming data from an API using Typescript and Lodash

First and most importantly, change your policy about using any for unstable APIs. Typescript is an incredibly powerful tool for making it possible to work with ...
Gerrit0's user avatar
  • 3,456
3 votes

Create list of objects from an object where the key is properCase using Lodash

The code looks like you're passing the processed data to autocomplete. Naming formatToInput: This gives no idea of what the function is doing. ...
Tushar's user avatar
  • 3,002
3 votes

Concat a collection's sub arrays and merge their parent

This can be done natively: ...
Joseph's user avatar
  • 25.1k
3 votes

Convert object array to hash map using lodash

With Lodash 4: Using keyBy and mapValues ...
tu4n's user avatar
  • 131
3 votes
Accepted

Check deep object property and find duplicate value

A very fun question, which took way too much time to analyze ;) It would have helped tremendously if you could have given a sample JSON instead of a screenshot. Regardless, if you are using lodash ...
konijn's user avatar
  • 33.2k
3 votes
Accepted

Create new array by filter origin array

So essentially, you're just getting the unique configuration IDs. This can easily be done by converting your aConfigurations into an array of IDs and using ...
Joseph's user avatar
  • 25.1k
2 votes
Accepted

Generating an HTML table with colspan and rowspan from a one-dimensional array

I really wanted to find a purely functional solution to this problem, but I wasn't able to. Nevertheless, your basic idea is pretty simple, and can be made even shorter and more declarative: ...
Jonah's user avatar
  • 4,340
2 votes

lodash get method equivalent in javascript

You can try the following script as alternate approch which: Get a nested property of a complex object at any level of depth without using recursion. This script uses ...
GibboK's user avatar
  • 667
2 votes

lodash filter array of objects by array of exclude property values

Use _.differenceWith() to exclude the items: ...
Ori Drori's user avatar
  • 211
2 votes

Filter one array based on values of another, is this the best way?

It may make sense to turn voucher.categories into a Set (or store them in a Set instead of ...
RoToRa's user avatar
  • 11k
2 votes

Filter one array based on values of another, is this the best way?

Normally there are a lot of categories, so I'd go through the voucher.categories array: ...
lgonzalo's user avatar
2 votes
Accepted

Transform an object into another object structure

So you have five data series here right (A through E)? What happens when you have 4 or 6 data series? Do you really want to rewrite your code? Also, unless you have some reason to do so, lodash ...
Mike Brant's user avatar
  • 9,618
2 votes
Accepted

Recursive component JSON configuration builder

Good things This code uses const for variables that don't get re-assigned. The functions are concise, though some of the lines are a bit long due to ternary ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes
Accepted

Finding optimal mapping patterns that transform relational data into a linear format

Some slight improvements: You could do without the result array (less state 🙌). I think using vanilla object destructuring is more clear than the lowdash ...
Mohrn's user avatar
  • 370
2 votes
Accepted

Counting duration values

First point Don't add quotes around property names when defining JS objects. ...
Blindman67's user avatar
  • 22.1k
2 votes

Counting duration values

To reduce the verboseness of the code, you should extract the main idea of that code into a function: ...
Roland Illig's user avatar
  • 21.3k
2 votes
Accepted

Compare two arrays of objects and get the objects based on ids

Use Map to reduce search complexity Currently your method is rather complex at \$O(n^2)\$. The reason is that for each Id you iterate each item to locate the one with the Id you want. You can use a <...
Blindman67's user avatar
  • 22.1k
2 votes

Javascript: Reducing redundancy of notation nested value

Undefined Information is missing in regard to the function's possible inputs. I will make a guess as to what the possibilities are in the rewrites TypeScript To use TypeScript and gain any benefit you ...
Blindman67's user avatar
  • 22.1k
1 vote
Accepted

Checking if any competitors have a non-empty name

I assume you are using lodash library. You may use _.some function. Checks if predicate returns truthy for any element of collection. Iteration is stopped once predicate returns truthy. The ...
sineemore's user avatar
  • 1,785
1 vote
Accepted

What's a cleaner way to pass a function an array of values and then sort my object by those values?

Lodash provides orderBy (formerly sortByOrder), as mentioned in this answer. Something like this might work: ...
aghast's user avatar
  • 12.4k
1 vote

Convert object with 'long.property.name' property to object tree

If I had to take a stab at it I would write something like this: ...
Marc Rohloff's user avatar
  • 3,477
1 vote
Accepted

Create an array which contains specific values of a specific nested object inside an array

You could use _.reduce() (or alternatively native Array.reduce()) to achieve this: ...
Mike Brant's user avatar
  • 9,618

Only top scored, non community-wiki answers of a minimum length are eligible