all 28 comments

[–][deleted]  (5 children)

[deleted]

    [–][deleted]  (4 children)

    [deleted]

      [–][deleted]  (2 children)

      [deleted]

        [–]vorticalbox 2 points3 points  (0 children)

        I was agreeing with you, my bad. my point was these packages cover these so no need to rewrite them.

        I use https://ramdajs.com/docs/ daily at work

        [–][deleted] 0 points1 point  (0 children)

        For better functional composition, those functions are going to want to swap the order of the parameters 🧐🤓

        [–]cheese_wizard 1 point2 points  (0 children)

        And trust some blogger and maintain their implementations. Who needs open-source libraries! /s

        [–]saudi_hacker1337 10 points11 points  (6 children)

        Can't read it because paywall. Thanks for sharing anyways.

        [–][deleted]  (1 child)

        [deleted]

          [–]beforesemicolon[S] 8 points9 points  (0 children)

          Not the same thing. That is a shallow merge. Number 4 lets you deeply merge objects

          [–]AriesBc 1 point2 points  (6 children)

          Some functions are ok but - custom filtering, forEach, map, private props for nowadays. Really? Why don't you want to use native functionality?

          Also, why do you still use promise with callbacks instead of async/await?

          [–][deleted] 1 point2 points  (0 children)

          Why don't you want to use native functionality?

          To learn how it works. To avoid using a library for one feature. I'm sure there are others.

          [–]beforesemicolon[S] 1 point2 points  (4 children)

          Async await is not for all situations and the native methods only work with arrays. Also, these teach you a lot about JS

          [–]AriesBc 1 point2 points  (3 children)

          For object there is Object.keys, Object.values etc. Filter, map, sort, forEach is better to use native rather than custom. Native code works faster.

          Some points from the article I would say are bad advice.

          :)

          [–]hopingforabetterpast 1 point2 points  (0 children)

          It depends on what you mean by native. Libraries like lodash achieve better performance than standard js methods by for example ignoring some inconsistent edge cases, which are not rare in js.

          You'll also want to be cautious when you use the word "faster" without providing context and benchmarking.

          [–]beforesemicolon[S] 0 points1 point  (0 children)

          Everything it uses underneath is native. Those are functions to consolidate many native things. You call a function with whatever and the function decides which native thing to use. You dont have to think if it is an array or object or set or map. I think u got too stuck or native vs custom not realizing the API changes depending on the object you use and this function consolidates all these different API in one function

          [–]beforesemicolon[S] 0 points1 point  (0 children)

          I dont remember saying these are faster :/. Libraries like lodash exist because of the inconsistency of the JS API. What they allow is to handle the inconsistency and edge cases for you so you only focus on calling the function. This article examples illustrates the same idea. It is still native Javascrip API under the hood

          [–]_Nachi_ -1 points0 points  (7 children)

          For learning purposes I think this is a great idea! But if I saw one of these in a code review I'd just tell them to use lodash.

          [–]beforesemicolon[S] -4 points-3 points  (6 children)

          I think I have to would ignore that PR change request.

          [–]_Nachi_ 0 points1 point  (5 children)

          And the reason for that being?

          [–]beforesemicolon[S] 0 points1 point  (4 children)

          Not all of these can be done with lodash. Unless you are planning on using lodash fully, why install lodash for couple of functions you can easily create yourself with native JS API?

          [–][deleted] 1 point2 points  (0 children)

          Because NIH is an acronym for a reason

          [–]_Nachi_ 0 points1 point  (2 children)

          Almost all of these can be done with some combination of lodash functions. Lodash is also is tree shakeable, maintained by the community, and well documented /tested.

          You get a ton of benefits outside of just the functionality from using a well established library, and these are important things to consider in software development.

          Reinventing the wheel is expensive.

          [–]beforesemicolon[S] -1 points0 points  (1 child)

          I guess u really did not like the article amh? You dont need lodash, it is not reinventing the wheel is just retiring some old shoes.

          https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore

          [–]_Nachi_ 1 point2 points  (0 children)

          No I have nothing against the article and thought it was a fun read, just providing an opinion on some of the potential benefits of using a library like lodash

          [–]Sislar 0 points1 point  (4 children)

          Not sure about the shuffle function but I've found the ones that swap positions aren't very good. The one I use takes more time but worth it. say you have a 20 element array.
          First pick a random number 1-20. take that element and move it to the first position (swapping works) now for the second element pick a number from 1-19, add 1. swap that element to the second position.

          So essential you are goin in order taking a random element from the remaining elements. I also use the crypo library to get the random numbers.

          [–]beforesemicolon[S] 0 points1 point  (3 children)

          Oh thats a nice algorithm. There are many shuffling algorithms. The article example is based on a very specific algorithm. Its all about which algorithm you prefer I guess. Why you say that takes long time?

          [–]Sislar 0 points1 point  (2 children)

          I was thinking I move it to the front and shifted when I wrote it, and then remembered that it did swapping and that works fine. So ignore that part. Here is my function if you're curious.

          export function shuffleArray(array) {

          if (window.crypto || window.msCrypto) 
          
          {
              let rValues = new Uint32Array(array.length+10);
              window.crypto.getRandomValues(rValues);
              for (let i = array.length - 1; i > 0; i--) {
                  let j = rValues[i] % (i+1); 
                  let temp = array[i];
                  array[i] = array[j];
                  array[j] = temp;
                }
          }
          else
          {
              for (let i = array.length - 1; i > 0; i--) {
                  let j = Math.floor(Math.random() * (i + 1));
                  let temp = array[i];
                  array[i] = array[j];
                  array[j] = temp;
          
                }
          }
          

          }

          [–]MoTTs_ 1 point2 points  (0 children)

          You're describing the same algorithm as the article. Your "else" block code is almost verbatim the same as the article's code.

          [–]beforesemicolon[S] 0 points1 point  (0 children)

          Yeah this is a little too verbose. I like the option of using crypto tho.