Striving to become a master Go/Cloud developer; Father ๐จโ๐งโ๐ฆ; ๐ค/((Full Stack Web|Unity3D) + Developer)/g; Science supporter ๐ฉโ๐ฌ; https://coder.today
Some side notes about the differences between the custom maps:
it pre-allocates the result array (we already know its length) const result = new Array(length)
it uses const where the values don't change (like the result and length)
both implementation lacks the last 2 optional parameters from the builtin Map functionality
by not using a for loop and storing the length, is not required to fetch the this.length value for each iteration
it doesn't pollute the global space (lodash export the functions, and you use them as you need), and most important it doesn't "modify" all instances of arrays from the entire project, I mean for many reasons it is bad to do
Array.prototype.ownMap
Yes, it's only for educational purpose. Thank you for giving a good example with notes and made this post better. I will certainly take a deeper look in lodash now.
Striving to become a master Go/Cloud developer; Father ๐จโ๐งโ๐ฆ; ๐ค/((Full Stack Web|Unity3D) + Developer)/g; Science supporter ๐ฉโ๐ฌ; https://coder.today
Lodash is a good example of an open source library that adds a huge value in your project, especially in the pre-JS6 era.
As for its code, as with any big open-source project, it has the added value from many of its contributor expertise. Crowd anything is general better then what a small team can achieve on its own.
Very nice as an example, just remember is an example that doesn't fully replace the builtin function, so don't use it in production.
As a completion, here is the lodash map source code
Some side notes about the differences between the custom maps:
const result = new Array(length)
this.length
value for each iterationArray.prototype.ownMap
Yes, it's only for educational purpose. Thank you for giving a good example with notes and made this post better. I will certainly take a deeper look in lodash now.
Lodash is a good example of an open source library that adds a huge value in your project, especially in the pre-JS6 era.
As for its code, as with any big open-source project, it has the added value from many of its contributor expertise. Crowd anything is general better then what a small team can achieve on its own.
Yap, You are right. Take a look in some popular library code and learn in that way. I will personally take that path in future. Thank you for advice.