📌  相关文章
📜  javascript给定范围如何确保数组包含所有值? - Javascript代码示例

📅  最后修改于: 2022-03-11 15:01:14.357000             🧑  作者: Mango

代码示例1
// 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.