Drill

ProblemsJavaScript › warmup

Initials for an avatar

easywarmupJavaScript

The user menu shows initials when someone has no profile picture.

initials(fullName: string) → string

Solve it in the editor →

Where you start

function initials(fullName) {
  
}

Worked examples

CallResult
initials("ada lovelace")"A.L."
initials("Grace Brewster Hopper")"G.B.H."
initials(" linus ")"L."
initials("")""

Hint

Split on whitespace, drop the empty pieces, then take index 0 of each.

Reference solution in JavaScript
function initials(fullName) {
  let out = '';
  for (const w of fullName.split(/\s+/)) {
    if (w) out += w[0].toUpperCase() + '.';
  }
  return out;
}

The same problem in another language

More warmup problems in JavaScript