function isEqual(arr1,arr2){ let x = arr1.length; let y = arr2.lenght; //if lenght of array are not equal means array are not equal if(x != y) return false; //sorting both array x.sort(); y.sort(); // Linearly compare elements for(let i=0;i<x;i++){ if(x[i] != y[i]) return false } // If all elements were same. return true } let arrayOne = [3, 5, 2, 5, 2] let arrayTwo = [2, 3, 5, 5, 2] isEqual(arrayOne,arrayTwo) ? console.log("Matched") : console.log("Not Match")
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter