I am looking to extract elements from an array, then store them in a new array and compare them to another array. The challenge is that I do not want to extract the elements in a specific order. I have tried using the .slice function for extracting elements in a specified order.
let winArray = [playerSymbol, playerSymbol, playerSymbol]
if (playingFielddArray.slice(0, 3).every(v => winArray.includes(v))) {
// Do something }
While this method works well, it only applies to ordered elements. For non-sequential elements, my approach involves creating multiple arrays for comparison.
let newArray = [playingFielddArray[0], playingFielddArray[4], playingFielddArray[8]]
if(newArray.every(v => winArray.includes(v))){ // Do something }
However, I find this solution cumbersome as it requires creating numerous arrays for comparison purposes. Is there a more efficient function or method that I can utilize for this task?