Find the number of true in the array.

Create a function trueCount which returns the number of true values in the array.


trueCount([false, true, false, true, false]) ➞ 2

trueCount([true, true, true, true]) ➞ 4

trueCount([]) ➞ 0


const count_true = r => r.filter(Boolean).length


function trueCount(arr) {
const trueCount = arr.reduce((total, item)=>total+Number(item), 0)
return trueCount;

You May Also Like

About the Author: Sunil Yadav

Hi, This is Sunil Yadav, I am full stack dev. I have a passion for learning and sharing my knowledge with others as publicly as possible.

Leave a Reply

Your email address will not be published.