Skip to content

Instantly share code, notes, and snippets.

@JacobBennett
Created May 4, 2017 17:00
Show Gist options
  • Save JacobBennett/68f12bceebcbdfadb16f4ab4f486d0c3 to your computer and use it in GitHub Desktop.
Save JacobBennett/68f12bceebcbdfadb16f4ab4f486d0c3 to your computer and use it in GitHub Desktop.
Challenge Solution
let getRandBetween = function(min, max) {
Math.random() * (max - min + 1) + min;
}
let getRandCoord = function(minX, minY, maxX, maxY) {
let opt = function() {
return Math.random() > 0.5;
};
return opt() ?
{
x: opt() ? minX : maxX,
y: getRandBetween(minY, maxY)
}
:
{
x: getRandBetween(minX, maxX),
y: opt() ? minY : maxY
};
};
@rankogit
Copy link

rankogit commented May 6, 2017

3 corrections I think...
-getRandBetween does not return anything
-i think getRandBetween should be ...return Math.random() * (max - min) + min;
-You are assigning a 25% chance the point you will return will be on each side of the rectangle. But if you really wanted to give equal chance of any point on the rectangle coming up then you would expect that a rectangle with that is 100 units high and only 1 unit wide will almost definitely return a point on one of its vertical sides but that's not what's happening here.

I could be misunderstanding the problem but that's my current interpretation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment