Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.9k views
in Technique[技术] by (71.8m points)

求数组中最短字符串长度 用reduce

比如 var arr=["flight", "flow", "flower"];

最短 'flow'

我印象中。。。。
arr.reduce((c,p)=>{return c.length<p.length?c.length:p.length})

我这是错误的写法 忘记如何写了 求大佬更正


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Array.prototype.reduce 实现

arr.reduce((c, p) => c.length < p.length ? c : p);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...