字符串连接算法挑战
function spinalCase(str) {
let result = str.replace(/(\b[A-Z])|([A-Z])|(\s+)|(\_)/g, (match, $1, $2, $3, $4) => {
if ($1) {
return $1.toLowerCase();
} else if ($2) {
return '-' + $2.toLowerCase();
} else if ($3) {
return '-';
} else if ($4) {
return '';
}
});
return result;
}