How to check if all values in array are true with TypeScript

2 Answers

0 votes
function arrAllValuesTrue(arr : any) : boolean {
    return arr.every(element => element === true);
}
 
const arr = [true, true, true, true, true, true];
 
console.log(arrAllValuesTrue(arr)); 
 
console.log(arrAllValuesTrue([true, false, true, true, true, true, 3]));
 
console.log(arrAllValuesTrue([true, 1, true, 2, true, 'typescript']));
 
   
   
   
/*
run:
   
true
false
false
   
*/

 



answered May 10, 2022 by avibootz
0 votes
function arrAllValuesTrue(arr : any) : boolean{
  	return arr.every(element => element);
}

const arr = [true, true, true, true, true, true];

console.log(arrAllValuesTrue(arr)); 

console.log(arrAllValuesTrue([true, false, true, true, true, true, 3]));

console.log(arrAllValuesTrue([true, 1, true, 2, true, 'typescript']));

  
  
  
/*
run:
  
true
false
true
  
*/

 



answered May 10, 2022 by avibootz

Related questions

2 answers 125 views
2 answers 117 views
2 answers 123 views
1 answer 129 views
1 answer 99 views
...