«RecursionPseudocode» Réponse de code

RecursionPseudocode
function buildWord(chars) {
  // base case:
  
  if chars' length is 1
    return the only char
  // induction:
  return first char + buildWord(chars minus the first char)
}
RecursionPseudocode
buildWord(['f', 'o', 'o'])
'f' + buildWord(['o', 'o'])
'f' + ('o' + buildWord(['o']))    // base case! return 'o' and fold
'f' + ('o' + ('o'))
'f' + ('oo')
'foo'

Laisser un commentaire