A collection of coding challenge/interview problems solved in JavaScript. Oftentimes a single file will declare the same function more than once (e.g. ./freeCodeCamp/fibonacci.js
); each subsequent definition is generally a more efficient version than what precedes it.
Also: solutions to (eventually) all exercises in Eloquent JavaScript.
Big Theta partial list of common functions in asymptotic notation, listed from slowest to fastest growing:
- Θ(1)
- Θ(lg n)
- Θ(n)
- Θ(n lg n)
- Θ(n²)
- Θ(n² lg n)
- Θ(n³)
- Θ(2^n)
###Constant Growth
A function has constant growth if its output does not change based on the input, n.
###Logarithmic Growth
###Linear Growth
A function has linear growth if its output increases linearly with the size of its input. If n is never raised to a power greater than 1 or used as a power, it is linear, e.g. 3n
.
###Linearithmic Growth
A function is linearithmic if we multiply linear terms by a logarithm, they take the form: n logK n. With n being equal in both, then the growth is dependent on the base k of the logarithms. Lesser bases grow more quickly than higher bases, so e.g. n log2 n will grow more quickly than n log6 n
###Polynomial Growth
A function has polynomial growth if its output increases according to a polynomial expression. The way to identify polynomial functions is to find those where n is raised to a constant power, e.g. 2n³
or 3n³
.
###Exponential Growth
A function has exponential growth if its output increases according to an exponential expression. The way to identify exponential funcitons is to find those where a constant is raised to some expression involving n, e.g. 2^n
or (3/2)^n
.
###Debugger Steps:
- add a
debugger
statement in a function - call the function manually
$ node inspect index.js
- to continue execution of file, press 'c' then 'enter'
- to launch a repl session, type 'repl' then 'enter'
- to exit the repl, press Ctrl + C