Created
December 18, 2011 20:39
-
-
Save digal/1494392 to your computer and use it in GitHub Desktop.
Solution for http://www.kurilo.su/programmers/
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
if (direction == '') { | |
direction = 'east'; | |
} | |
var dirs; | |
var look = function (dir) { | |
if (dir == 'north') return north; | |
else if (dir == 'south') return south; | |
else if (dir == 'east') return east; | |
else if (dir == 'west') return west; | |
} | |
if (direction == 'north') | |
dirs = ['east', 'north', 'west', 'south']; | |
else if (direction == 'west') | |
dirs = ['north', 'west', 'south', 'east']; | |
else if (direction == 'south') | |
dirs = ['west', 'south', 'east', 'north']; | |
else if (direction == 'east') | |
dirs = ['south', 'east', 'north', 'west']; | |
for (var i=0; i<=3; i++) { | |
var dir = dirs[i]; | |
var dir_look = look(dir) | |
if (dir_look == 3 || dir_look == 0) { | |
console.log('returning ' + dir); | |
result = dir; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment