- 用reduce求和
// 用reduce求和
const sum = [1,2,3,4,5,6].reduce((previousValue,currentValue) => {
return previousValue+ currentValue
},0)
- 将this-is-an-example 变为 This Is An Example
//将this-is-an-example变为This Is An Example
const joined = "this-is-an-example"
.split("-")
.map(word=>{
const [head,...others] = word
return head.toUpperCase()+others.reduce((x,y)=>x+y,"") // others.join("")
})
//["This","Is","An","Example"]
.reduce((s,word) => {
return s+ " "+word
})
console.log(joined)