getInitials

Easy · String Manipulations · 2 test cases

Given a full name, return the initials.

Examples

getInitials('John Doe') → 'JD'
getInitials('First Middle Last') → 'FML'

Starter code

function getInitials(name) {

}

Complexity of the optimal solution

Time O(n), space O(n). The complexity is determined by the `split` operation which iterates through the string of length n to create an array of words. The `map` and `join` operations also depend on the number of words, which is related to n.

Solve getInitials in the browser