Is This the Most Useful JavaScript Method?

Поділитися
Вставка
  • Опубліковано 19 січ 2025
  • Methods such as map(), filter(), every() & reduce() are useful, but which one would you choose if you couldn't use one of the other 3 again? Let's find out.
    For your reference, check this out:
    developer.mozi...
    🏫 My Udemy Courses - www.udemy.com/...
    🎨 Download my VS Code theme - marketplace.vi...
    💜 Join my Discord Server - / discord
    🐦 Find me on Twitter - / dcodeyt
    💸 Support me on Patreon - / dcode
    📰 Follow me on DEV Community - dev.to/dcodeyt
    📹 Join this channel to get access to perks - / @dcode-software
    If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
    #dcode #javascript

КОМЕНТАРІ • 15

  • @EricEGunes
    @EricEGunes 6 місяців тому +7

    Absolutely!!! Reduce() ! You can do same jobs if you know how to!
    - but
    the performance results for processing an array of 100,000 elements:
    • map() took approximately 0.044 seconds
    • reduce() took approximately 19.010 seconds

    • @beratyilmaz7951
      @beratyilmaz7951 6 місяців тому

      not true, write your code so we can test it

    • @raven.4815
      @raven.4815 6 місяців тому

      A whooping 19 secs? That's absolute madness

  • @alexanderkomanov4151
    @alexanderkomanov4151 6 місяців тому

    Nice one! Thanks!

  • @marshallgraphic
    @marshallgraphic 6 місяців тому

    I don't think result && ... will reassign the value to result, or am I mistaking the prev result is the value of the previous return value?

    • @mimosveta
      @mimosveta 6 місяців тому

      it will

    • @dcode-software
      @dcode-software  6 місяців тому +1

      Yeah it works because once it reaches the first element that gives "false", the value can't ever evaluate to "true" ever again because we use &&

  • @mimosveta
    @mimosveta 6 місяців тому

    I knew of it for few years, and basically never used it, but I think I will start now... I guess I'll first use it to translate other methods to reduce, just to get used to it...

    • @dcode-software
      @dcode-software  6 місяців тому

      Yeah sure, but of course, I'm not suggesting you replace "map" with "reduce". If the method exists for the purpose then definitely use it. This video is more for education

  • @usagiakimbo2506
    @usagiakimbo2506 6 місяців тому

    Good examples, thanks for this

  • @bmehder
    @bmehder 6 місяців тому +1

    reduce() is the god method

  • @suelingsusu1339
    @suelingsusu1339 6 місяців тому

    Beautiful.... 👌👌👌👌👌👏👏👏👏🙏🙏🙏🙏🌹🌹🌹🌹🌹🖖🖖🖖🖖🖖🖖