1. Minimun function
// min funcion
function min(num1, num2) {
if (num1 > num2)
return num2;
else
return num1;
};
console.log(min(7, 16));
2. isEven function
I have avoided multiplication by -1 by doing the addition for negative numbers
// isEven with negative support
function isEven(number) {
if (number == 0)
return console.log(true);
else if (number == 1)
return console.log(false);
else if (number < 0)
isEven(number + 2);
else
isEven(number - 2);
};
isEven(50);
3. Bean counting function
// countBs funcion V1.0
function countBs(string) {
let count = 0;
for(let pos=0; pos < string.length; pos++){
if(string[pos] == "B")
count++
}
return count;
};
console.log(countBs("abBa"));
console.log(countBs("BabBaB"));
Here is the function for any char
function countChar(string, char) {
let count = 0;
for(let pos=0; pos < string.length; pos++){
if(string[pos] == char)
count++
}
return count;
};
// countBs funcion V1.0
function countBs(string) {
return countChar(string, “B”);
};