Created
July 10, 2014 13:33
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
var poder = function(name, last){ | |
var conrta = []; | |
for (var i = conrta.length - 1; i >= 0; i--) { | |
conrta[i] | |
}; | |
}; | |
function forEach(array, action){ | |
for(var i = 0; i < array.length; i++){ | |
action(array[i]); | |
} | |
} | |
simpleArray = [1,2,36, "pppp"]; | |
forEach(simpleArray, print); | |
var roads = new Object(); | |
function makeRoad(from, to, length){ | |
function addRoad(from, to){ | |
if(!(from in roads)) | |
roads[from] = []; | |
roads[from].push({to: to, distance: length}); | |
} | |
addRoad(from, to); | |
addRoad(to, from); | |
} | |
function roadsFrom(place){ | |
var found = roads[place]; | |
if(found == undefined) | |
throw new Error("No place named " + place + " found."); | |
else | |
return found; | |
} | |
function gamblerPath(from, to){ | |
function randomInteger(below){ | |
return Math.floor(Math.random() * below); | |
} | |
function randomDirection(from){ | |
var options = roadsFrom(from); | |
return options[randomInteger(options.length)].to; | |
} | |
var path = []; | |
while(true){ | |
path.push(from); | |
if (from == to) | |
break; | |
from = randomDirection(from); | |
} | |
return path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment