Random nonzero values in an interval.(Common Lisp)

(defun random-weight ()
  "Return a random value in [-1,1), but never zero.  Typically used to
initialize input weights."
  (loop as r = (1- (random 2.0))
        thereis (unless (zerop r) r)))

vs

Choose your favorite, or:

Add Code

Want to peek at the scoreboard?

View Slickest
View Slackest

Expanding Date(Javascript)

Date.prototype.getWeekday = function(weekdayArray){
  // Type String would fiddle things up. object, number, function return 'undefined' on length method.
  try {
    if (weekdayArray && weekdayArray.length === 7) {
      typeof weekdayArray == 'string' ? function(){throw "TypeException"}() : this.weekdays = weekdayArray;
    }
  }
  catch(exception) { 
    alert(exception + ": optional param of Date.getWeekday() must be an Array, not "+ typeof weekdayArray);
  };
  return (this.weekdays||["Sun","Mon","Tue","Wed","Thur","Fri","Sat"])[this.getDay()]; 
};

Date.prototype.getMonthname = function(monthsArray) { 
  // Type String would fiddle things up. object, number, function return 'undefined' on length method.
  try {
    if (monthsArray && monthsArray === 12) {
      typeof monthsArray == 'string' ? function(){throw "TypeException"}() : this.months = monthsArray;
    }
  }
  catch(exception) { 
    alert(exception + ": optional param of Date.getMonthname() must be an Array, not "+ typeof monthsArray);
  };
  return (this.months||["January","February","March","April","May","June","July","August","September","October","November","December"])[this.getMonth()]; 
};