shabashj
9/2/2015 - 10:32 AM

May and Nice way to solve this kata From http://www.codewars.com/kata/55b1fd84a24ad00b32000075/solutions/javascript

var AmIAfraid = function(day, num){
  //the straight way
  
  switch(day){
    case "Sunday":
      return (num === 666 || num === -666) ? true: false;
    case "Monday":
      return (num === 12) ? true: false;
    case "Tuesday":
      return (num > 95) ? true: false;
    case "Wednesday":
      return (num === 34) ? true: false;
    case "Thursday":
      return (num === 0) ? true: false;
    case "Friday":
      return ((num%2) === 0) ? true: false;
    case "Saturday":
      return (num === 56) ? true: false;
  }  
}

//nice way
var AmIAfraid = function(day, num) {
  var preds = {"Sunday":    d => d == 666 || d == -666,
               "Monday":    d => d == 12,
               "Tuesday":   d => d > 95,
               "Wednesday": d => d == 34,
               "Thursday":  d => d === 0,
               "Friday":    d => d % 2 === 0,
               "Saturday":  d => d == 56};
  return preds[day](num);
}