Skip to content

Instantly share code, notes, and snippets.

@jorydotcom
Created August 4, 2012 02:01
Show Gist options
  • Save jorydotcom/3253507 to your computer and use it in GitHub Desktop.
Save jorydotcom/3253507 to your computer and use it in GitHub Desktop.
My answers to @rmurphey's Assessment problems
//Also from https://gist.github.com/3164584
//My first attempt to solve Problem 2:
function watWord(num) {
switch (num) {
case 1:
return "one";
case 2:
return "two";
case 3:
return "three";
case 4:
return "four";
case 5:
return "five";
case 6:
return "six";
case 7:
return "seven";
case 8:
return "eight";
case 9:
return "nine";
case 10:
return "ten";
default:
return false;
}
};
//Switch statement works fine for a small amount of numbers, but what if I wanted to do this for 1-100?
//Also noting that the default takes care of validating input
//From https://gist.github.com/3164584
//This is the way I immediately want to solve this:
function bigOrSmall(arg) {
var number = arg;
if (number < 10) {
return "small";
}
else if (number > 9 && number < 101) {
return "medium";
}
else {
return "large";
}
};
//After some thought:
function bigOrSmall(arg) {
if (arg > 100) {
return "large";
}
else if (arg > 9 && arg < 101) {
return "medium";
}
else {
return "small";
}
};
//Saving the variable in the first solution doesn't appear to give me any benefit.
//Also made more sense to work from "large" to "small" as there are more numbers that fall into the first case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment