Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js compare lists

// compare two arrays where order might differ
const array1 = [1,2,3,4,5];
const array2 = [3,4,1,2,5];

const compareArrays = (array1, array2) => {
  return (
    array1.length === array2.length && 
    array1.every((el) => array2.includes(el));
  );
};

compareArrays(array1, array2); // true
 
PREVIOUS NEXT
Tagged: #js #compare #lists
ADD COMMENT
Topic
Name
8+5 =