Last active
February 3, 2018 01:03
-
-
Save djorborn/6c68752b6688e5325e323f445c74ba8b to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/qaxorop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
// I want to see if array contains all of the numbers in arr; | |
var x = [0, 2, 7, 6]; | |
var o = [4, 1, 3, 5]; | |
var win = [ | |
[0, 1, 2], | |
[3, 4, 5], | |
[6, 7, 8], | |
[0, 4, 8], | |
[2, 4, 6], | |
[0, 3, 6], | |
[1, 4, 7], | |
[2, 5, 8] | |
]; | |
function checkStuff(array, win){ | |
var nArr = []; | |
for(var i = 0; i < array.length; i++){ | |
for(var j = 0; j < win.length; j++){ | |
if( array[i] == win[j] ) { | |
nArr.push(array[i]) | |
} | |
} | |
} | |
return nArr; | |
} | |
for(var s = 0; s < win.length; s++){ | |
if(checkStuff(x, win[s]).length == 3){ | |
console.log("x wins"); | |
break; | |
} else if (checkStuff(o, win[s]).length == 3){ | |
console.log("o wins"); | |
break; | |
} | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">// I want to see if array contains all of the numbers in arr; | |
var x = [0, 2, 7, 6]; | |
var o = [4, 1, 3, 5]; | |
var win = [ | |
[0, 1, 2], | |
[3, 4, 5], | |
[6, 7, 8], | |
[0, 4, 8], | |
[2, 4, 6], | |
[0, 3, 6], | |
[1, 4, 7], | |
[2, 5, 8] | |
]; | |
function checkStuff(array, win){ | |
var nArr = []; | |
for(var i = 0; i < array.length; i++){ | |
for(var j = 0; j < win.length; j++){ | |
if( array[i] == win[j] ) { | |
nArr.push(array[i]) | |
} | |
} | |
} | |
return nArr; | |
} | |
for(var s = 0; s < win.length; s++){ | |
if(checkStuff(x, win[s]).length == 3){ | |
console.log("x wins"); | |
break; | |
} else if (checkStuff(o, win[s]).length == 3){ | |
console.log("o wins"); | |
break; | |
} | |
}</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I want to see if array contains all of the numbers in arr; | |
var x = [0, 2, 7, 6]; | |
var o = [4, 1, 3, 5]; | |
var win = [ | |
[0, 1, 2], | |
[3, 4, 5], | |
[6, 7, 8], | |
[0, 4, 8], | |
[2, 4, 6], | |
[0, 3, 6], | |
[1, 4, 7], | |
[2, 5, 8] | |
]; | |
function checkStuff(array, win){ | |
var nArr = []; | |
for(var i = 0; i < array.length; i++){ | |
for(var j = 0; j < win.length; j++){ | |
if( array[i] == win[j] ) { | |
nArr.push(array[i]) | |
} | |
} | |
} | |
return nArr; | |
} | |
for(var s = 0; s < win.length; s++){ | |
if(checkStuff(x, win[s]).length == 3){ | |
console.log("x wins"); | |
break; | |
} else if (checkStuff(o, win[s]).length == 3){ | |
console.log("o wins"); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment