10 ms·
Classic Algorithms Implemented in JavaScript
- jtbayly 8y agoLove the beginner/advanced tags. Also, just generally well-organized. This is great.
- ggm 8y agoNicely done git web. Love these things done "right"
- cachesking 8y agoIt would be cool if these had tests around them where it made sense.
- acqq 8y agoAlready there: https://github.com/trekhleb/javascript-algorithms/blob/master/src/data-structures/bloom-filter/__test__/BloomFilter.test.js https://github.com/trekhleb/javascript-algorithms/blob/maste...
- cachesking 8y agoBeautiful. Apparently, I was not paying attention.
- k__ 8y agoWhat I would wish for is a list of common problems and how certain algorithms and data structures solve them.
- brian_cloutier 8y agoI recommend Skiena's "The Algorithm Design Manual", it also includes some fun war stories of real world problems he was called in to solve, and the algorithms he used to solve them.
- uncletaco 8y agoWell its not a list per se but many of the interview prep sites tag their problems with the appropriate algorithm/data structure for the job. As someone who has his first SV phone technical interview on Monday and has done ~30 problems in the last two weeks, I can say after solving about 2-3 of them over a number of hours or days you start to recognize which algorithm will get the job done from the problem descriptions.
- k__ 8y agoInteresting :D Would be nice if you could post a list of your resources :)
- throwaway080383 8y agoNot OP, but I used leetcode extensively while prepping for interviews and it worked out well for me. Like she/he said, just spend a few hours a day doing these problems; I even went back to problems I'd previously solved to see if I could write out the correct code in one shot.
- hackandtrip 8y agoNot OP, but a resource commonly suggested is "Cracking the Coding interview"
- azundo 8y agoWould recommend checking out the algorithm design manual if you're looking for a book with that sort of approach. Edit: just noticed this was already recommended below, take this as another strong endorsement!
- BanazirGalbasi 8y agoAs poor as I did in my Algorithms class last semester, this would have been very helpful to reference. There's definitely a gap between the concept and implementation of CS concepts, being able to see an efficient implementation of something like Heap Sort really helps teach how it works.
- cybrix12 8y agoCool list but I would like to see them being implemented using FP approach when possible.
- wcarron 8y agoYou can always fork it and make a PR
- skrebbel 8y agoI'm impressed by the commenting. This is much higher quality stuff than I expected!
- deleted 8y ago[deleted]
- mad_cow 8y agoNo FizzBuzz?
- emodendroket 8y agoNot really the kind of thing people usually mean when they talk about "algorithms."
- LolNoGenerics 8y agoLets pretend JS arrays had no queue api, why whouldn't I use native arrays to implement a queue?
- jwdunne 8y agoDoesn't look like a utility belt but a reference. If I want to know how queue is implemented by example, using the native queue methods wouldn't help whatsoever.
- sbjs 8y agoThis is amazing! I’ve forked this with plans to translate all of it to TypeScript, which really just means adding <T> about 10 times per file, erasing the java doc comments and replacing them with actual parameter types. Still worth it!
- cabalamat 8y agoThe implementation of a hash table uses a hash table, which feels like cheating to me. Also I suspect that adding together the ascii values of the characters in the key is not necessarily the best hash function.
- uncletaco 8y agothe keywords "ill" and "duh" will cause collision. I know this because I ran into this issue trying to be clever on leetcode's anagram grouping problem.
- austincheney 8y agoUsing what hash mechanism? I tested with SHA512 and got different results: * ill - 2ae60a99f87408af77066079879865d907201ff44e7b1f26d911afcd1097c4c32162b97546c404d3a305396698ea530d3c3690adb7dcbc91ec685837f895a37b * duh - e44e6d93cd165ec8cdeaa632abe1c35d9a71533cc68072e100c5307ea3be17bc4f10e258785bef77d31664be0f1c3f427528c7450d52082a90c4ee86c7012184
- jovial_cavalier 8y agoAdding their ASCII together, they both yield 321.
- uncletaco 8y agoWhat jovial said. Adding ascii yields the same integer for ill and duh.
- throwaway080383 8y agoYeah, there are 26^n length n strings of lowercase alphabetical characters, but only ~26*n different hashes with that function.
- paidleaf 8y ago> Also I suspect that adding together the ascii values of the characters in the key is not necessarily the best hash function. Still better than using the length of the string as your hash value. Not my proudest moment but sometimes, you want to see the world burn. That and I forgot to do my hw and class was in a few minutes.
- uptownJimmy 8y agoSuper job! As someone currently studying this stuff, this is a gold mine. It's hard to interview in this field if you didn't get a CS degree, and this sort of gesture is forever appreciated.
- booleandilemma 8y agoIt’s hard to interview in this field even with a CS degree, unfortunately. The problem is there are too many people interviewing, with and without CS degrees.
- uptownJimmy 8y agoI haven't run into the "too many people interviewing" problem, though I am not the interviewer. My main issue is definitely the whiteboard portion of the competition. Complaining about those whiteboard skills being of negligible daily use on the job is getting me nowhere: the only solution is to study up. My strongest language is JS, so this repo is really, really nice.
- amelius 8y agoIt'd be nice if they made the distinction between functional/immutable data structures and mutable ones.
- devmunchies 8y agoits pretty interesting to see the steep curve for how many stars this repo has collected in such a short amount of time http://www.timqian.com/star-history/#trekhleb/javascript-algorithms http://www.timqian.com/star-history/#trekhleb/javascript-alg...
- blt 8y agoGreat resource, but I couldn't help laughing at the plot with asymptotic complexity classes categorized as "horrible, bad, fair, good, excellent", as if it's independent of the problem.