function countSheeps(arrayOfSheep) { let count = 0 for (const sheep of arrayOfSheep) if (sheep === true) { count++ } return count } function countSheeps(arrayOfSheep) { return arrayOfSheep.filter(sheep => sheep).length } function countSheeps(arrayOfSheep) { //return arrayOfSheep.filter(sheep => sheep).length return arrayOfSheep.reduce((total, sheep)=>{ return sheep ? total+=1 : total }, 0) }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter