Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 1.14 KB

README.md

File metadata and controls

36 lines (27 loc) · 1.14 KB

Four Funcs

my solution to Mihai Bazon's little puzzle

sort of done it in 6 lines...depending on how long your line is and how long you name your variables yada yada yada

The problem

Define functions range, map, reverse and foreach, obeying the restrictions below, such that the following program works properly. It prints the squares of numbers from 1 to 10, in reverse order.

var numbers = range(1, 10);
numbers = map(numbers, function (n) { return n * n });
numbers = reverse(numbers);
foreach(numbers, console.log);

/* output:

   100
   81
   64
   49
   36
   25
   16
   9
   4
   1
*/

Restrictions

  • You must not use arrays. The square bracket characters, [ and ], are forbidden, as well as new Array.
  • You must not use objects. The curly braces, { and }, and the dot character (.) are forbidden. You may use curly braces for code blocks, but not for creating JavaScript objects.
  • Should go without saying, these functions must be generic and do what their name implies. They must not be hard-coded for the particular 1..10 example.