Checking that a Predicate is True for All Typescript Array Elements


We have an array of elements [1,2,'a'] , and we want to see whether all of the elements in the array are numbers.


This approach uses:

@fireflysemantics/validatorts to check whether the array element is a number:

let arr: any[] = [1, 2, 'a'];function allNumbersPredicate(v: any, index: number, array: any[]):boolean {
console.log(`is number ${isNumber(v).value}`);
return isNumber(v).value;
console.log(`All numbers:? ${arr.every(allNumbers)}`);




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ole Ersoy

Ole Ersoy

Founder of Firefly Semantics Corporation