function calWinner(arr) {
//winning combination
const winningIds = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6],
]
for (let i = 0; i < winningIds.length; i++) {
calculate(arr, winningIds[i])
}
}
function calculate(sup, sub) {
sup.sort()
sub.sort()
let i = 0
let j = 0
for (i, j; i < sup.length && j < sub.length;) {
if (sup[i] < sub[j]) {
++i
} else if (sup[i] == sub[j]) {
++i, ++j
} else {
return false
}
}
return j == sub.length;
}
calWinner([1, 3, 7, 4])
I'm trying to write a function that takes an array, and check if it has every element in a nested array in an object inside of the function.
I've added a function I found from this post, but not sure why i am getting undefined instead of true.