Skip to content

Instantly share code, notes, and snippets.

//Verison 0
'use strict';
var counterFactory = function counterFactory() {
return function() {};
};
var firstCounter = counterFactory();
// firstCounter contains a reference to
// a new instance of the minimal function
@gaand
gaand / age.js
Last active October 6, 2015 15:02
var age = function age() {
var dob = new Date(this.dob);
var today = new Date();
var thisYear = today.getFullYear();
if (dob.getMonth() > today.getMonth() ||
dob.getMonth() === today.getMonth() &&
dob.getDate() >= today.getDate()) {
thisYear -= 1;
}
@gaand
gaand / transform.md
Last active October 5, 2015 20:30
Transomation
'use strict';

var transform = function transform(value, predicate, mutator) {
  if (predicate(value)) {
    return mutator(value);
  }
  return value;
};
var height = 69;
var arrayTimes2 = function arrayTimes2(array) {
  for (var i = 0; i < array.length; i++) {
    array[i] *= 2;
  }
};
@gaand
gaand / product.md
Last active October 5, 2015 19:19
product, two version
var product2 = function product2(nums) {
var result = 1;

  for (var i = 0; i < nums.length; i++) {
    result *= nums[i];
  }

  return result;
@gaand
gaand / max.md
Created October 5, 2015 19:15
Max
var max = function max() {
  // grab the first number to compare against
  // this will be undefined if arguments is empty
  var maxValue = arguments[0];
  // loop through the remaining numbers
  for (var i = 1; i < arguments.length; i++) {
    // if the current element is greater
    // than the maxValue
 if (arguments[i] &gt; maxValue) {