Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function sequence(startCount, newCount) {
  
  var currentCount = startCount;
  
  return function counter() {
      currentCount += newCount;
      return currentCount;
  };
}
function take(gen, x) {
  
  var mas = [];
  
  for (var i = 0; i < x; i++) {
    mas.push(gen());
  }
  return mas;
}
function square(number) {
  return number * number;
}
var counter = sequence(1, 3);
var gen = take(counter, 5);
function fmap(square, counter) {
  return function () {
    return square(counter());
  };
}
var squareCounter = fmap(square, counter);
function map(square, array) {
  var arrayCopy = array;
  for (var i = 0; i < arrayCopy.length; i++) {
    arrayCopy[i] = square(arrayCopy[i]);
  }
  return arrayCopy;
}
var array = [1, 2, 3, 4];
console.log(map(square, array));
console.log(array);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers