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.codewars.com/kata/do-you-speak-english/train/javascript
function spEng(sentence){ //write your code here return RegExp(/english/ig).test(sentence); }
function spEng(s){ return /english/i.test(s) }
https://www.codewars.com/kata/filter-out-the-geese/train/javascript
function gooseFilter (birds) { var geese = ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"]; // return an array containing all of the strings in the input array except those that match strings in geese var arr = []; for(i in birds){ if(!(geese.indexOf(birds[i])>-1)){ //has this element arr.push(birds[i]); } } return arr; };
function gooseFilter (birds) { var geese = ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"]; return birds.filter(b => !geese.includes(b)); };