0

how could i create a function that takes in a function and a string and logs the result of calling the function on each letter in the string

function logger() {
}

function parse(letter) {
  return letter.toUpperCase().concat('yo').split('').slice(1).join('');
}

logger(parse, 'hello world')

Essentially i want each character in the string "hello world" to be replaced with yo. My code can only be in the section below

function logger() { }

1 Answers1

0

Just like that:

function logger(fct, str) {
  console.log(fct(str))
}

function parse(letter) {
  return letter.toUpperCase().concat('yo').split('').slice(1).join('');
}

logger(parse, 'hello world')
Mickael B.
  • 4,755
  • 4
  • 24
  • 48