Skip to content

Instantly share code, notes, and snippets.

@mr-fool
Last active August 29, 2015 14:09
Show Gist options
  • Save mr-fool/662c61f4559466ac42ad to your computer and use it in GitHub Desktop.
Save mr-fool/662c61f4559466ac42ad to your computer and use it in GitHub Desktop.
exercise 3 minimum
function countChar(string, ch) {
var counted = 0;
for (var i = 0; i < string.length; i++)
if (string.charAt(i) == ch)
counted = counted + 1;
var str1 = "The " + string + " contains " + ch + " at position " + i + ",";
var str2 = " and the total number of " + ch + " is " + counted + ".";
var result = str1.concat(str2);
return result;
}
function countBs(string) {
return countChar(string, "B");
}
console.log(countBs("ABC"));
console.log(countChar("kakkerlak", "k"));
var math = function(num1, num2) {
var mini = num1;
if (mini > num2) {
mini = num2;
}
return mini;
};
console.log(math(2,1));
function isEven(num) {
if (num === 0) {
return true;
}
else if (num === 1) {
return false;
}
else if (num < 0) {
return isEven(-num);
}
else {
return isEven(num - 2);
}
}
console.log(isEven(50));
console.log(isEven(75));
console.log(isEven(-1));
console.log(isEven(-2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment