January 2018
Intermediate to advanced
332 pages
7h 36m
English
Let's take a Fibonacci generator, for example, and brute-force the generation of some numbers:
var _ = require('lodash');var count = 10;bruteForceFibonacci(count);function bruteForceFibonacci(count) { var prev = 0; var next = 1; var res = ''; res += prev; res += ',' + next; _.times(count, ()=> { var tmp = next; next = prev + next; prev = tmp; res += ',' + next; }); console.log(res);}
Here, we can see that we are not applying any domain knowledge; we simply take the two previous numbers from the series and add them. This is a fine way of doing it, but we can see that there are some improvements to be made here.
Read now
Unlock full access