JSFiddle - React, Tailwind, and code Playground

by Andrey

JavaScript

var allNumbers = [1, 2, 4, 5, 6, 7, 8],
    someNumbers = [1, 2, 'привет', 4, 5, 'loftschool', 6, 7, 8],
    noNumbers = ['это', 'массив', 'без', 'чисел'],
		noArr = '123',
    empty = [];
    
function isAllTrue(arr, func){
	var e = new Error();
	
  if(typeof func !== 'function'){
     	e.message = 'No Function';
      e.name = 'no function';
      throw e;
     }
     else if(arr.length === 0){
     	e.message = 'Array is empty';
      e.name = 'empty array';
      throw e;
     }
     else if(typeof arr !== 'array'){
     	e.message = 'No Aray!';
       e.name = 'no array';
       throw e;
     }
  
  
  for(var i = 0; i<arr.length; i++){
  
    if(func(arr[i])){}
     else { 
         return false;
     }
      
  };
 
  return true;

};

function isNumber(val){
  return	typeof val == 'number';
};
function isString(val){
	return typeof val == 'string';
};

try {
	console.log(isAllTrue(empty, isNumber));
  } catch(e){
  	console.log(e.message);
  };