Get partial string match of string Array using Lodash

I have an array of strings and want to find partial string matches using Lodash. I’d like the search to find full matches (such as with broken) but also partial matches (such as with virus being part of viruses) const textToSearch = ‘The broken ship that caught fire also had viruses onboard’; const arrayOfKeywords =… Read More Get partial string match of string Array using Lodash

How to use _.groupby() and import _ using lodash-es

I recently used import { keyBy } from ‘lodash-es’; in my code.Similarly I also want to import _ for using _.groupby() in lodash. I am confused on how to use _.groupby() using lodash-es. I tried using import { _ } from ‘lodash-es’; Here is my output: Uncaught SyntaxError: The requested module ‘/node_modules/.vite/deps/lodash-es.js?v=afbadbd5’ does not provide… Read More How to use _.groupby() and import _ using lodash-es

How to refactor this to provide the property name (string)?

The following is working code. The question is specifically about refactoring to provide the string for property name used to compare by isSame. Perhaps better renamed to isPropValueSame. import * as _ from ‘lodash’; const diff = _.differenceWith(sourceList, comparatorList, this.isSame); isSame = (objA: any, objB: any) => (_.has(objA, ‘id’) && _.has(objB, ‘id’) ? objA[‘id’] ===… Read More How to refactor this to provide the property name (string)?

How to Invert nested array/objects structure and rekeying by lowest object?

I have lodash 4.17 available I have the following API response structure: { "things": [ { "id": 14500, "name": "Q1 Out Ind", "thing_type_id": 6, "owner_id": 1680, "owner": { "id": 1680, "model_id": 602 }, "thing_type": { "id": 6, "name": "The Type of Thing" }, "related_things": [ { "id": 9749, "name": "unnamed thing", "thing_id": 14500, "more_things": [… Read More How to Invert nested array/objects structure and rekeying by lowest object?

Inserting Object Into Array Alphabetically From Nested Key Value

My app makes a http call and returns an array of objects. I need to loop over the objects and insert in to a new array in alphabetical order. Problem is the last item in the newly created array is the only item out of order. Example code: https://stackblitz.com/edit/typescript-zh16xc?file=package.json,index.ts Aware i can use the native… Read More Inserting Object Into Array Alphabetically From Nested Key Value

JS: Group array of time related objects by today, yesterday, last 7 days, and months

I have the following case. Assuming I have an array like this: const listOfObjects = [ { title: "Title", date: "timestamp from today" }, { title: "Title", date: "timestamp from yesterday" }, { title: "Title", date: "timestamp from yesterday" }, { title: "Title", date: "timestamp from one day in the last seven days" }, {… Read More JS: Group array of time related objects by today, yesterday, last 7 days, and months

Debounce function called multiple times

I call following function within useEffect. useEffect(() => { loadData(); }, [amount]); loadData function uses Lodash debounce function. When I update amount from input, loadData gets called several times depending on length of amount string. const loadData = useCallback( debounce(() => { console.log(‘called!’); // Fetch data from API … }, 1000), [amount] ); In spite… Read More Debounce function called multiple times