Big O notation is used to discuss how things grow as the dataset gets larger. It is not strictly limited to runtime, and is never in fact measuring runtime. It is simply a way of mathematically approximating how things grow.
It can be used to talk about the number of operations performed, number of comparisons used, memory required, memory allocations, etc. Its all in how you slice the code and determine what the most costly factors are. Whatever is most costly will generally have the biggest impact on runtime/performance.
In this case, memory allocations are the most costly part of the algorithm. And making 1 allocation, versus 3N + 1 allocations is the part that effects both the runtime and memory usage the most.
@FArekkusu where can we find out why it was retired?
Doing this math in milliseconds is a super bad idea, and completely unnecessary.
You could have used lodash's range() method generate the months array and turn this into a one liner.
Pretty efficient except for one line:
This would be more efficient as:
new Date(year, 0)
Mixing let and var is not "best practice".
Split/Join is significantly less efficient than replace.
Always use curly braces on if statements for readability and maintainability.
toCharArray() creates a copy of the string. You should always avoid this method.
Do not use toCharArray(), it causes the string to be copied, where a copy is not necessary.
n >= arr.length
Doesn't work for all test cases.
Needs a test case where some words are a substring of previous words.
Example: "starborn star"
Fails for case "starborn star"