This is a variation of example 7-15 from
The Book of JavaScript
, by Dave Thau.
Number 1:
Number 2: