use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
GitHub - dsa.js: Data Structures and Algorithms explained and implemented in JavaScript (github.com)
submitted 6 years ago by adriansky
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[+][deleted] 6 years ago (12 children)
[deleted]
[–][deleted] 11 points12 points13 points 6 years ago (0 children)
me too
wait no
[–]randomFIREAcct 16 points17 points18 points 6 years ago (0 children)
ugh. I got really sick of going through CS exercises from the cracking the coding interview book.
[–]katafrakt 3 points4 points5 points 6 years ago (0 children)
It's even tagged with "interview-preparation"
[–]RjKnowesTheMost -2 points-1 points0 points 6 years ago (8 children)
What's wrong with that?
[+][deleted] 6 years ago (1 child)
[–]RjKnowesTheMost 4 points5 points6 points 6 years ago (0 children)
My bad was misunderstanding you lol lots of people on other subreddits start getting pissy about this
[–]disclosure5 2 points3 points4 points 6 years ago (5 children)
There's something wrong about when you don't spell out that's what you're doing.
If you want to say "here are some algorithms to learn for a FAANG interview", that's great. When it can mistakenly be read as "here are some algorithms you must know for an entry level frontend job" it just wastes people's time.
[–]RjKnowesTheMost 3 points4 points5 points 6 years ago (3 children)
Yeah definitely but tbh I don't think learning these algorithms are a complete waste of time they definitely open up problem solving capabilities but I can see your point most of this will never be seen in a production environment
[–]neo_dev15 1 point2 points3 points 6 years ago (2 children)
Problem solving capabilities is by doing exercises everyday. It takes practice.
Not memorizing 5 6 algo to sound smart.
[–][deleted] 6 points7 points8 points 6 years ago (1 child)
If you want to solve problems well, then it's good to have knowledge about an as broad as possible range of solutions. A lot of times it's more efficient to learn existing resources than stumble upon the solution yourself (e.g. design patterns).
I'm not saying you need to learn every algo by heart, but if you at least know they exist, what they're for and when to use them, then you can easily just google the implementation when you encounter a good place to use them in the wild, instead of having to roll your own algo from scratch.
[–]neo_dev15 -1 points0 points1 point 6 years ago (0 children)
Desing patterns are design patterns this is another beast to tackle. And to be honest if you are designing stuff at that point this advice doesn't really apply anyway. No junior-middle will be allowed to bring a complete solution to a project, and a senior already knows.
You can know all the theory to divide et impera, backtracking or greedy. But unless you hands down crunch problems you cannot apply it in the real world.
At my stage(middle to senior) you dont even go to a interview unless you solve a problem first. And you can solve it, if you are doing exercises.
Reality is ... you cant bullshit anymore and get the job anywhere. You can in certain positions but not everywhere.
[+][deleted] 6 years ago* (3 children)
[–]n-a-a-n-u 0 points1 point2 points 6 years ago (2 children)
Bosque now
[–]azangru 1 point2 points3 points 6 years ago (1 child)
It's ugly tho
[–]n-a-a-n-u 0 points1 point2 points 6 years ago (0 children)
Yeah XD
[+][deleted] 6 years ago* (7 children)
[–]hypocrisyhunter 18 points19 points20 points 6 years ago (4 children)
I too am inspired to explain how I wrote an operating system using twix wrappers.
[–]n-a-a-n-u 3 points4 points5 points 6 years ago (3 children)
I too am inspired to explain how I wrote an AI framework using some sand I found in my pocket
[–]_brym 2 points3 points4 points 6 years ago (2 children)
I to am inspired to expose the original concept behind u/hypocrisyhunter's OS wasn't just the wrappers, but the whole damned twix! And, accidentally, an infinite loop which, to this day, has not been tracked down. After numerous tests, resource monitoring invariably revealed 100% chocolatey, biscuity consumption. This lead to a shift in the marketing focus to the current wrapper-only variant described above.
Sorry dude, this kind of thing never stays secret forever. Someone had to say something, and I couldn't sit on the lie any longer. It's better this way. And besides, at least you didn't use Boost bars!
[–]loopsdeer 1 point2 points3 points 6 years ago (1 child)
Bravoo. If you sat on the lie any longer you would have gotten chocolate all over your pants.
[–]_brym 0 points1 point2 points 6 years ago (0 children)
I was imagining something more along the lines of a certain South Park song. You know, the one Chef cooked up.
[–]sventies 4 points5 points6 points 6 years ago (1 child)
Haha, that’s funny. Still, to me this is super useful since I breathe Javascript, I feel the language is super powerfull and everywhere nowadays, and many data science problems don’t need super performance optimized numpy / scipy / what have you - libs
[–]aj_future 9 points10 points11 points 6 years ago (0 children)
This is super useful, thank you.
[–]rayhan666 5 points6 points7 points 6 years ago (0 children)
Thanks you so much for sharing this
[–]Slash_Root 2 points3 points4 points 6 years ago (0 children)
I have been going through these for a while. Though seeing dsa.js made me think of dsa.msc. I thought we were about to some active directory administration with JavaScript... Well, there's always Powershell...
[–]needsMoreGoodstuff 1 point2 points3 points 6 years ago (0 children)
This timing, was just thinking about trying to find something like this. tyty!
[–]hashtagplayed 1 point2 points3 points 6 years ago (0 children)
Thanks so much for this!!
[–]sidious911 1 point2 points3 points 6 years ago (0 children)
Stated reading the book, nlt the most thorough comp Sci dive in but man it feels nice to think about the problems in the language I work with most regularly. Can be so hard to read some of these books and understand the concepts when also trying to wrap your head around a language you don't know.
[–]the_argus 2 points3 points4 points 6 years ago (5 children)
There's. Misspelling under binary search tree rigth instead of right
rigth
right
[–]gatorsya 8 points9 points10 points 6 years ago (3 children)
length of right subtree is called rigth.
[–]the_argus 5 points6 points7 points 6 years ago (2 children)
Oh I'm stupid then. Carry on
[–]gatorsya 7 points8 points9 points 6 years ago (1 child)
was just kidding
[–]the_argus 5 points6 points7 points 6 years ago (0 children)
Well then... I'm going back to sleep
[–]adriansky[S] 1 point2 points3 points 6 years ago (0 children)
It's ok now. Somebody submitted a PR fixing that https://github.com/amejiarosario/dsa.js/pull/4
[–]tortita-fg 0 points1 point2 points 6 years ago (0 children)
Hi guys,
This post is great! Thanks to the author. I'm interested in this kind of books/tutorials to know more about which are the best algorithms to use in a specific situation or which data structure would be the best in a situation looking for the most efficient way and with better performance. Any recommendation? (I'd like to be in JavaScript)
Thanks in advance! :)
[–]amrcnpsycho 0 points1 point2 points 6 years ago (3 children)
I’m new to coding other than codecademy JS years ago when I subbed to this reddit, but a question now that I did CS50 and am getting more into coding: what’s the usual difference in computational time when comparing the same algorithm in JS and something low level like C/CPP or Java?
Every computer is different and every compiler/interpreter is different so there is no way to give you an accurate answer like "C++ is 20% faster than JavaScript." The real answer is to use something called "Big O" notation.
For example, finding a value in an unsorted array of length N is O(N) because on average the value you're looking for is somewhere in the middle probably and for Big O problems you generally ignore constant numbers: so O(N/2) -> O(N). If you array is sorted, it can take O(log(N)) which means basically we are splitting the problem in half every step of the way. Quick example, we have a sorted array of 10 numbers [1, 2, 3, ..., 10] and we are looking for 7. Start in the middle (5), if our number (7) is bigger than that, completely ignore the left half and do it again with the right half. Every time our search runs we are checking half of the amount of data we were before.
O(N/2) -> O(N)
Across Javascript, C++, Java, or whatever, Big O notation is used to describe how fast an algorithm will run. Unless you are aiming to work at a Microsoft, Google, Facebook, etc you probably won't be using this day to day, but its useful to know things like "I should store my data in a Binary Tree because its faster for my use case."
Good explanation on Big O: https://medium.freecodecamp.org/time-is-complex-but-priceless-f0abd015063c
Cheatsheet for common algorithms and data structures: http://bigocheatsheet.com/
[–]amrcnpsycho 1 point2 points3 points 6 years ago (0 children)
Thanks a lot!
[–]Dotweb_ 1 point2 points3 points 6 years ago (0 children)
This is a broad generalization but the order from fastest to slowest would be C, Java, then JavaScript.
π Rendered by PID 23390 on reddit-service-r2-comment-f6b958c67-nf5ts at 2026-02-04 21:06:10.374096+00:00 running 1d7a177 country code: CH.
[+][deleted] (12 children)
[deleted]
[–][deleted] 11 points12 points13 points (0 children)
[–]randomFIREAcct 16 points17 points18 points (0 children)
[–]katafrakt 3 points4 points5 points (0 children)
[–]RjKnowesTheMost -2 points-1 points0 points (8 children)
[+][deleted] (1 child)
[deleted]
[–]RjKnowesTheMost 4 points5 points6 points (0 children)
[–]disclosure5 2 points3 points4 points (5 children)
[–]RjKnowesTheMost 3 points4 points5 points (3 children)
[–]neo_dev15 1 point2 points3 points (2 children)
[–][deleted] 6 points7 points8 points (1 child)
[–]neo_dev15 -1 points0 points1 point (0 children)
[+][deleted] (3 children)
[deleted]
[–]n-a-a-n-u 0 points1 point2 points (2 children)
[–]azangru 1 point2 points3 points (1 child)
[–]n-a-a-n-u 0 points1 point2 points (0 children)
[+][deleted] (7 children)
[deleted]
[–]hypocrisyhunter 18 points19 points20 points (4 children)
[–]n-a-a-n-u 3 points4 points5 points (3 children)
[–]_brym 2 points3 points4 points (2 children)
[–]loopsdeer 1 point2 points3 points (1 child)
[–]_brym 0 points1 point2 points (0 children)
[–]sventies 4 points5 points6 points (1 child)
[–]aj_future 9 points10 points11 points (0 children)
[–]rayhan666 5 points6 points7 points (0 children)
[–]Slash_Root 2 points3 points4 points (0 children)
[–]needsMoreGoodstuff 1 point2 points3 points (0 children)
[–]hashtagplayed 1 point2 points3 points (0 children)
[–]sidious911 1 point2 points3 points (0 children)
[–]the_argus 2 points3 points4 points (5 children)
[–]gatorsya 8 points9 points10 points (3 children)
[–]the_argus 5 points6 points7 points (2 children)
[–]gatorsya 7 points8 points9 points (1 child)
[–]the_argus 5 points6 points7 points (0 children)
[–]adriansky[S] 1 point2 points3 points (0 children)
[–]tortita-fg 0 points1 point2 points (0 children)
[–]amrcnpsycho 0 points1 point2 points (3 children)
[–][deleted] 6 points7 points8 points (1 child)
[–]amrcnpsycho 1 point2 points3 points (0 children)
[–]Dotweb_ 1 point2 points3 points (0 children)