DEV Community

10 Popular JavaScript methods implemented from scratch

Artem Verbitski on January 10, 2022

Introduction In this article I wanted to share with you with the most popular JavaScript methods but implemented by scratch. A little un...
Collapse
 
northwillov profile image
Artem Verbitski

Yes, I totally agree with you.
You don't have to know how car engine works inside to drive a car, what I meant was
knowing how car engine works, makes you a better understanding of a car itself.

And you may be surprised but assembly language is still in use, so knowing such stuff definitely makes you a better dev 😜.

Cheers!

 
northwillov profile image
Artem Verbitski

These are only a light versions of "the engine". So we won't get a full understanding of it, but a light one.

For those who want to familiarize with the internals of JS methods e.g. Array.prototype.map you can find this information here: developer.mozilla.org/en-US/docs/W...

Thanks πŸ˜€

Collapse
 
antongolub profile image
Anton Golub

sort should work in place:

10. Repeat, while j < itemCount,
a. Perform ? Set(obj, ! ToString(𝔽(j)), items[j], true).
b. Set j to j + 1.
Enter fullscreen mode Exit fullscreen mode

tc39.es/ecma262/#sec-array.prototy...
developer.mozilla.org/en-US/docs/W...

Collapse
 
northwillov profile image
Artem Verbitski • Edited

Hi!
These are only a light versions of popular methods in JS, and of course the original methods mentioned in ECMAScript are much more complex and useful.
Thank you for comment :)

Collapse
 
biglogic profile image
Big-Logic

Nice. Fundamentals are worth knowing. Developers are like engineers who build engines, so if you don’t understand how a single part of the engine you want to build works, than you are going to be some kind of mere dev because trial and error are what you are going to be on all times.

Collapse
 
lepinekong profile image
lepinekong

It's not the same thing as rebuilding a car engine, but it shows he knows javascript and datastructure. Sometimes you need an original algorithm if you software is a bit innovative, if you just do lame integration work then it's ok you don't need to understand much.

 
lepinekong profile image
lepinekong • Edited

I don't say ALL integration work are lame, I say that there are integration work that are lame that's why they are automatable why do you think lowcode/nocode are now rising and usable by just business people ;) dev.to/lepinekong/comment/1l7ab

Collapse
 
prabhukadode profile image
Prabhu

Useful

Collapse
 
oskarcodes profile image
Oskar Codes

Good article, but you forgot to include the return -1 for .indexOf

Collapse
 
northwillov profile image
Artem Verbitski

Thanks for noticing! I made an update.

 
lepinekong profile image
lepinekong • Edited

I do SystemThinking : things are not separate ;) If I recruit a coder I will indeed want to be sure he master the fundamentals if not I would rather recruit the guy/girl for doing lowcode or nocode.

Collapse
 
the_yamiteru profile image
Yamiteru

Are these implementations faster than native ones?

Collapse
 
medan_in_code profile image
MedanInCode

Nice Post

Collapse
 
rajesh6161 profile image
Rajesh Ranjan

Good try but most of the Algorithms are wayyyyyy too slow to use, for example, your sort algorithm is taking O(N^2) time too slow.

Collapse
 
northwillov profile image
Artem Verbitski

As ECMAScript doesn’t specify any sorting algorithm to be implemented by Array.prototype.sort(), it totally depends on browser which sorting algorithm to be implement.

Safari, Webkit, etc. uses 'Selection Sort' whereas Mozilla uses 'Merge Sort'.

The sorting algorithm behind .fakeSort() mentioned in this article is 'Bubble Sort', and is intended for educational purposes and isn’t an efficient method for sorting in real world.

Bubble Sort also is one of the most widely discussed algorithms, simply because of its lack of efficiency for sorting arrays. If an array is already sorted, Bubble Sort will only pass through the array once, however the worst case scenario is a run time of O(NΒ²), which is extremely inefficient.

Some comments have been hidden by the post's author - find out more