natural numbers algorithm templates for JavaScript