假如我有这样2个函数:
function capitalize (string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}
function hyphenate (strings) {
let hyphenated = ''
strings.forEach((str, idx, strs) => {
if (idx === strs.length - 1) {
hyphenated += capitalize(str)
} else {
hyphenated += capitalize(str) + '-'
}
})
return hyphenated
}
我现在想让hyphenate
不再依赖capitalize
, 有什么好的方法吗?
相关分类