02/12/2022
πππ Tips- #24
Make cartesian products of two or more arrays recursively.
π° A cartesian product of two arrays is a permutation of all possible arrays of two elements whose first element belongs to the first array and the second element belongs to the second array.
π° For two arrays it's easy to generate the cartesian products but for more than two arrays it's a little complex.
The concept is easy. First, make the cartesian products of the first two arrays, keep the product in a new array and then repeat the process for the next arrays with the product array.
π° From this snippet you can learn:
β How to combine two or more arrays to generate cartesian products.
π¬ So, what do you think? Can you implement this using a recursive function? If you then don't forget to share a snippet.
π° Playground - https://lnkd.in/gkuYvxrY
π° Follow me on Twitter - https://twitter.com/ahamed_sajeeb
25/11/2022
πππ Tips- #23
π° A clean and modern approach for finding out the intersecting items from two arrays using Set.
The idea is simple: Create two Sets by using the two arrays and then iterate over any of them. If an element of the iterating Set exists on the other Set then this element intersects, otherwise it's not.
π° From this snippet you can learn:
β How to find the common items of two arrays.
β How to iterate over a Set
β How to check if an element exists in a set or not using the Set.has() method.
π¬ So, what do you think? Can you implement this using a recursive function? If you then don't forget to share a snippet.
π° Playground - https://lnkd.in/gZZ7wvX9
π° Follow me on Twitter - https://twitter.com/ahamed_sajeeb
20/11/2022
πππ Tips- #22
π° Attach a new Component to another Component using JSX dot notation. By using this you can attach a component to another component and you don't need to do any explicit export/import for using the attached component.
βDid you see this pattern before? Of course, you did. Just remember the you've used in your application.
π° From this snippet you can learn:
β How to attach a new component to another component using JSX dot notation.
β How to use composite components in react.
π¬ So, what do you think? Can you implement this using a recursive function? If you then don't forget to share a snippet.
π° Follow me on Twitter - https://twitter.com/ahamed_sajeeb
16/11/2022
πππ Tips- #21
π° Get all the descendents of an item from an array of id-parentId relationships. We are using stack (LIFO) data structure for traversing and gathering the descendents IDs.
π° From this snippet you can learn:
β How to use Stack data structure using an array.
β How to get all the descendents from a specific node.
π¬ So, what do you think? Can you implement this using a recursive function? If you then don't forget to share a snippet.
π° Playground - https://lnkd.in/e9cnBuZf
π° Follow me on Twitter - https://twitter.com/ahamed_sajeeb
02/11/2022
πππ Tips- #20
π° Passing some extra data to the event handler function using curring. We often need to pass some extra data to event handler functions, and for doing that we pass this as a param along with the event object. Instead of doing this, we can use the curring technique for passing required extra data to the event handler function.
π° From this snippet you can learn:
β How to use curried functions
β How to pass required extra data along with the event object.
π¬ So, what do you think? If you have any other good solutions then feel free to share your thoughts.
π° Follow me on Twitter - https://twitter.com/ahamed_sajeeb
29/10/2022
πππ Tips- #19
π° Convert a linear data structure with a multi-way tree structure. Suppose you have an array of objects with "id", and "parent_id" values, you want to convert the structure such that all the children of a parent are situated inside a children's array of the parent item.
π° From this snippet you can learn:
β How to use recursion with typescript.
β How to convert a linear data structure to a multi-way tree structure.
π¬ So, what do you think? If you have any other good solutions then feel free to share your thoughts.
π° Playground - https://lnkd.in/gjk7Bx7Y
π° Follow me on Twitter - https://twitter.com/ahamed_sajeeb
09/10/2022
I've just reached 100 followers! Thank you for continuing support. I could never have made it without each and every one of you. ππ€π
08/10/2022
π Tips- #18
π§ Check if an array of objects has any duplicate entries for a specific property. In the function, there is a callback function as a second parameter by which the user can tell the function by which property you have to check the duplicate entries.
β From this snippet you can learn how to find if there are any duplicate entries conditionally from an array of objects according to a property.
π¬ So, what do you think? If you have any other good solutions then feel free to share your thoughts.
πΉPlayground - https://lnkd.in/gHcFS35N
π€ Follow me on Twitter - https://twitter.com/ahamed_sajeeb
22/09/2022
π Tips- #17
π§ Find the edge value (max or min) conditionally from an array of objects. The second parameter of the function is a callback function that gives the previous edge value and the current array item as parameters and the user can define the condition by which the edge value will be determined.
β From this snippet you can learn how to find the min or max object conditionally from an array of objects according to a property.
π¬ So, what do you think? If you have any other good solutions then feel free to share your thoughts.
πΉPlayground - https://lnkd.in/eViwfiTs
π€ Follow me on Twitter - https://twitter.com/ahamed_sajeeb
10/09/2022
π Tips- #16
π§ useDebounce hook for implementing debounce in react.
The idea is simple, keep an internal state and update the state after a specific delay time. If the given value is changed before the delay time passed, then cancel the timeout and wait for the delay time once again. And finally, return the debounced state value once the delay is passed.
β From this snippet you can learn how to create a custom hook to manage debounce in react JS.
π¬ So, what do you think? If you have any other good solutions then feel free to share your thoughts.
πΉGist - https://gist.github.com/ahamed/75b36b7f55b1b688d4cda8cbb4eecfe2
π€ Follow me on Twitter - https://twitter.com/ahamed_sajeeb
04/09/2022
π Tips- #15
π§ JavaScript introduces a new array method name `group`, but this is only added to the firefox nightly build. Here we can create a similar implementation of the `Array.prototype.group` method.
The `Array.prototype.group` method basically accepts a callback function as a parameter and groups the array elements according to the callback function's return key and returns an object. From the callback function, you have to return a string or a number.
β From this snippet you can learn how to handle your own callback function and use them accordingly.
π¬ So, what do you think? If you have any other good solutions then feel free to share your thoughts.
πΉGist - https://gist.github.com/ahamed/db0a1e2ec5d903f921274ce84489186e
π€ Follow me on Twitter - https://twitter.com/ahamed_sajeeb
25/08/2022
π Tips- #14
π§ Create an array from an array-like object. An array-like object is an object, which has a length property and indexed elements. Indexed elements mean the properties of the object are like the index of an array starting from 0.
β From this snippet you can learn how to use `Array.from()` method using the `length` property.
π¬ So, what do you think? If you have any other good solutions then feel free to share your thoughts.
πΉGist - https://gist.github.com/ahamed/313a0f7cf527ffbbb8b015094ee780fc
π€ Follow me on Twitter - https://twitter.com/ahamed_sajeeb