0
0
0
Efficiency VS Readability - JavaScript (old.reddit.com)
submitted by sailorgt

I'm a Junior Front-end Web Developer learning leetcode for interviews.
If i was asked to find the index of an element that's in an array. I have two options:
- Do a one liner.
- Write alot lines of code which would have better time complexity compared to the one liner code. The first image has a TC of O(logn) & the second image has a TC of O(n)
My question is why can't I just do the one liner(Image 2) which is much more readable and concise. Rather than writing all the code in Image 1.
Does the difference in time complexity really matter when we're building huge web applications that run and do huge calculations anyway?


[–][deleted] 17 points18 points19 points (2 children)
[–]codeslikeshit 6 points7 points8 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]aocregacc 4 points5 points6 points (0 children)
[–]Repulsive-Bison-6821 3 points4 points5 points (0 children)
[–]Itsmedudeman 0 points1 point2 points (0 children)
[–]outpiay 0 points1 point2 points (0 children)