Created
May 25, 2018 03:56
-
-
Save cosmo-naut/5183f4d3e4567386a73e82c4a15da8b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<script> | |
var array = []; | |
arrayX = 4; | |
arrayY = 4; | |
var rotate = ({oa}) => | |
{ | |
var na = []; | |
for (let i = 0; i < arrayX; i++) | |
{ | |
na[i] = []; | |
for (let j = 0; j < arrayY; j++) | |
{ | |
na[i][j] = oa[4 - j - 1][i]; | |
} | |
} | |
return na; | |
} | |
var log = () => | |
{ | |
for (let i = 0; i < arrayX; i++) | |
{ | |
console.log(array[i]); | |
} | |
} | |
for (let i = 0; i < arrayX; i++) | |
{ | |
array[i] = []; | |
for (let j = 0; j < arrayY; j++) | |
{ | |
array[i][j] = `${i}` + ` ${j}`; | |
} | |
} | |
console.log("Old Array:") | |
log(); | |
array = rotate({oa : array}); | |
console.log("New Rotated Array:") | |
log(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Little experiment to rotate an array using javascript.
I know it's n^2 but frankly I don't mind given the use case