spinalCase
Convert a string to spinal case. Spinal case is all-lowercase-words-joined-by-dashes.
Examples
spinalCase('This Is Spinal Tap') → 'this-is-spinal-tap'
Starter code
function spinalCase(str) {
}
Complexity of the optimal solution
Time O(n), space O(n). The regex-based split and subsequent join operations iterate through the string. The time taken and the space for the intermediate array are proportional to the string's length (n).