Last active
August 29, 2015 14:09
-
-
Save mr-fool/662c61f4559466ac42ad to your computer and use it in GitHub Desktop.
exercise 3 minimum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var math = function(num1, num2) { | |
var mini = num1; | |
if (mini > num2) { | |
mini = num2; | |
} | |
return mini; | |
}; | |
console.log(math(2,1)); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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