-
-
Save JacobBennett/68f12bceebcbdfadb16f4ab4f486d0c3 to your computer and use it in GitHub Desktop.
Challenge Solution
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
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 | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.