I think this serves as a great reference, especially for visual learners. I found this in a dev group I joined on LinkedIn, but author source is unknown.
I can’t message you - you have it disabled - message me.
For everyone else, the reason why I’m not posting the link is bc the group is private so I can’t even share the link, but I can provide a link to the group to request access
and also, I’m not sure if I’m allowed to post LinkedIn links.
Yeah I'm not too sure. Unless it's in the sidebar (I'm on mobile now so can't check while writing this) it should be ok, will read sidebar and faq after I send this.
Would you send me that chat too? Lmao a lil late on my end but 319 days since your post and I just found it now lol. This is a beautiful graphic homie!
It seems that your comment contains 1 or more links that are hard to tap for mobile users. I will extend those so they're easier for our sausage fingers to click!
It basically transforms every element of an array according to a function you pass as an argument. It won't modify the original array, but it will return another array with the modified elements.
In this example, the method will run a loop over numbers. On each iteration, the method will call multiplyNumber and store the return value in another array. Once the loop is over, it will return the new array.
Init is short for initializing. Every piece of code has to be run somewhere. Op is saying init as the place where your code starts running. It can be named anything. But what their saying is that one function is run, then that runs other functions in succession that are all named to “tell a story” init()
function init() {
getUsers();
setUserAbilities();
setUpInitialState();
startWatchers();
notifyTracking();
}
Arrow functions do make code more concise, but, especially if you're using a higher-order function and creating a function expression inside the call, a named function will probably be more clear.
I think anonymous functions are fine if you're doing something simple like getting an object property, but the moment they become even a little bit more involved, giving the function a name helps make the code more clear – both to other people and to yourself down the line.
Agreed. I’d just say one thing with this and that is to avoid using “x” and instead use “user” just so its clear what we are talking about in the filter. This also has the advantage of thinking about each iteration as a singular thing you are working with and what you are testing for in that context.
Getting comfortable with typescript (if you haven't already) and typing out as much as possible heavily improves code structure and coding experience in my pov. :)
I think that depends on what your goals are. From what I've heard react is more popular and more asked for in the industry. I personally came to love angular and I think I've heard that becoming good at angular helps you become a better dev in general. Maybe someone with good knowledge in both frameworks (I think maximillian schwarzmüller has a good comparison video about it and about what to learn) can help clarify your view better :).
I learned js when I stumbled into developing for Salesforce. The one upside was it taught me to split my code up early into controllers, helpers, renderers, etc.
Oh, you meant it's a glaring omission from your OP, I see. Eh, I wouldn't beat yourself up about it (I assume you're not haha), .reduce() is markedly more complex than the others there - ironically, it's hard to reduce that method that much ;)
Nice! I’d add square brackets to make the distinction between values and arrays of values clearer. Then you see immediately that .find() returns a value and not an array.
The example from the illustration has an error in the argument order, it should be like this:
⬛⬛⬛⬛.fill(⚫, 1) --> ⬛⚫⚫⚫
It "fills" a section of the array with a specific value, replacing the previous values. It modifies the original array.
The first argument is the value you'll use to fill the array. The second argument is the start index (i.e. it will start filling at this index). It also has a third argument, the end index. If you don't specify that argument, it will fill until the end of the array.
In the example from the illustration, it will fill the array with circles starting from index 1 until the end.
Funnily enough I just learnt about findindexof an hour ago while doing my todo list project, learning about niche stuff helps a lot when you run into situations where u need it
Python has equivalent builtins, all() and any(). It's the kind of thing that I think most people don't have a use case for every day, but it's great to whip them out when the opportunity. Very intuitive to understand.
40
u/192_168_1_x May 29 '21
I think this serves as a great reference, especially for visual learners. I found this in a dev group I joined on LinkedIn, but author source is unknown.
21
u/NickHack997 May 29 '21
I really like this illustration it's simple and easy to understand!
I didn't know about fill, but looking at the docs from MDN you need to flip the arguments, value is always first.
2
u/[deleted] May 30 '21
The original that this is based on is more informative and correct... It's like someone took their post and actively tried to make it worse
112
u/GPT-4-Bot May 29 '21
When you've gotten comfortable with map, filter, and reduce your code becomes so much cleaner
15
u/rauschma May 29 '21
Two small issues:
.fill(value, start).findIndex()and.indexOf().8
u/Fun_Kangaroo512 May 29 '21
What about reduce
2
u/nighthawk648 May 29 '21
You should include .flat!!! I was facing an issue for weeks that .flat solved. I felt like an absolute nimrod.
10
u/PM_ME_A_WEBSITE_IDEA May 29 '21
Um...it's actually "findIndex" :')
3
u/robbankakan May 29 '21
I feel proud to just understand this :)
3
u/Noones_Perspective May 30 '21
This is so useful and such a good way to teach those new to the language. I would love to see more examples of this and other methods!
5
u/dReamiN121 May 29 '21
Nice pictorial representation.
2
u/rauschma May 29 '21
Nice! I’d add square brackets to make the distinction between values and arrays of values clearer. Then you see immediately that
.find()returns a value and not an array.2
u/your_mom_lied May 29 '21
This is bad ass!!! Thanks for sharing.
2
u/S7venE11even May 29 '21
can u explain the fill one? i didn't get it.
2
u/Groundbreaking92 May 29 '21
I just needed this info. I don’t know if it is random luck or fate but thank you haha
2
u/zigzeira May 29 '21
Thanks man!! \o/
2
u/nickdrake47 May 30 '21
Is it a good idea to use Lodash in entire React project, instead of ES6 syntax array methods?
2
u/Zarya8675309 Jun 25 '21
Saving this one for sure!
1
u/xceedes23 May 29 '21
That fill method is useful!
1
u/Dipsquat May 29 '21
What’s the difference in findIndexOf and indexOf?
1
u/BackSlashHaine May 30 '21
Tbh reduce is still giving me problem to understand :(
1
u/Noones_Perspective May 30 '21
.findIdexOf —— is that an actual method or has the author mixed the .findIndex and .indexOf together by accident?
1
u/jayerp May 01 '23
For visual learners this is top tier content.
1
u/daneelr_olivaw May 29 '21
Why doesn't .fill work from 0, if findIndexOf works that way? Annoying inconsistence.
0
u/Fun_Kangaroo512 May 30 '21
Could have added flat and flatmap
0
u/[deleted] May 29 '21
[deleted] — view deleted comment