Chapter 2 Exercise Set 3

countDigits(s)

Write a function countDigits that takes a string, s, as an argument and returns the number of digits in s. countDigits("1, 2, buckle my shoe") should return 2, for example, and countDigits("no digits in here") should return 0.

count(ch, s)

Write a function named count that takes two arguments, a character, ch, and a string, s, and returns the number of times that ch appears in s. count("i", "Mississippi") will return 4, and count("x", "I am the Walrus") will return 0.

reverse(s)

Write a function reverse that takes a string, s, as an argument and returns a string with the letters of s in reverse order. reverse("cat") should return "tac" and reverse("JavaScript") should return "tpircSavaJ".

mirror(s)

Write a function mirror that takes a string, s, as an argument and returns the letters in s followed by the letters in s backwards. mirror("yes") should return "yessey" and mirror("JS") should return "JSSJ".

removeCharacter(ch, s)

Write a function removeCharacter that takes two arguments, a character, ch, and a string, s, and returns a string with all the characters in s execpt ch. removeCharacter("a", "apple") should return "pple". removeCharacter("a", "banana") should return "bnn", and removeCharacter("i", "Mississippi") should return "Msssspp".