How to check if all values in object are not equal in TypeScript

1 Answer

0 votes
function allValuesAreNotEqual(obj : any) {
    return new Set(Object.values(obj)).size !== 1;
}
 
const obj1 = {num1: 5, num2: 5, num3: 5};
console.log(allValuesAreNotEqual(obj1));
 
 
const obj2 = {num1: 1, num2: 8, num3: 9};
console.log(allValuesAreNotEqual(obj2));
 
   
   
   
   
/*
run:
   
false
true
   
*/

 



answered Apr 24, 2022 by avibootz

Related questions

1 answer 113 views
1 answer 114 views
1 answer 130 views
1 answer 121 views
1 answer 113 views
1 answer 126 views
1 answer 118 views
...