javascript given range how to make sure array contains all values? code example
Example: javascript given range how to make sure array contains all values?
// JavaScript - Given a range, how to check array contains all values?"
// Use of .every() & .includes() combined.
// Returns true or false.
let range = [1,2,3,4,5,6,7,8,9] // Use this array to repeatedly checking against, does not change.
let myArray = [8,6,7,5,3,1,2,4,9] // Array that fluctuates and checking for validity.
let checker = (myArray, range) => (
range.every(value => (
myArray.includes(value))
);
)
console.log(checker(myArray, range)); // true.