Write a function that returns how many times the string "code" appears in array.

function countCode(arr) {  
  
}

//Output: 
// countCode(["code", "code", "cool"]) returns 2
// countCode(["code", "code", "cool", "code"]) returns 3
// countCode(["coe", "ode", "cool", "pool"]) returns 0
Step it up

Write a function that returns the number of times that the string "code" appears anywhere in the given string, except we'll accept any letter for "d", so "cope" and "cooe" would also count.

  • Return the count, including any substitutions for the letter "d".
function countCode(string) {  
  
}

//Output: 
// countCode("aaacodebbb") returns 1
// countCode("codexxcode") returns 2
// countCode("cozexxcope") returns 2

Extra credit

  • Allow any uppercase characters to substitute for "c"