var countSheep = function (num){ //your code here var str = ‘ sheep...‘; var result = ‘‘; for (var i=1;i<num+1;++i){ result+=(i+str); } return result; }
CW解:
countSheep=n=>[...Array(n).keys()].map(x=>`${x+1} sheep...`).join``
var countSheep = function (n){ return [...Array(n)].map((_,i)=>i+1+‘ sheep...‘).join`` }
const countSheep = num => { let val = ‘‘; for (let i = 1; i <= num; i++) { val += `${i} sheep...`; } return val; }
原文地址:https://www.cnblogs.com/ukzq/p/10284365.html
时间: 2024-11-08 15:22:51