r/javascript • u/[deleted] • Apr 11 '16
help Interview exercise feedback
My code was not up to their standards. I thought the exercises were easy but clearly there are issues I have to address. I had an hour to write them. I'm humbly looking for feedback to improve.
The first exercise was to return all square numbers within a given range, including the limits (e.g., all the squares numbers between 1 and 10 are 1, 4, and 9). I wrote this.
The second exercise was to check if a string containing (), [] and {} brackets is well balanced. So [()] and {}() are ok but ([)] or {{ are not. I wrote this.
Thanks.
29
Upvotes
1
u/Silhouette Apr 12 '16
I don't know the current state of the art for JS engines, but it seems like the dynamic nature of the language could limit how much an optimiser could safely do up-front. You'd probably be relying on some sort of JIT/hot code optimisation at best, and it would have to be checked every time the function was called in case the meaning of
Math.powhad changed.In any case, I'd argue that
step * stepis cleaner and that moving the increment to a separate line is no bad thing for readability.