Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function treasureLocator(input) {
- const pointInRectangle =
- (x, y, xMin, xMax, yMin, yMax) =>
- xMin <= x && x <= xMax && yMin <= y && y <= yMax;
- function locate(x, y) {
- const islands = [
- ['Tokelau', 8, 9, 0, 1],
- ['Tuvalu', 1, 3, 1, 3],
- ['Samoa', 5, 7, 3, 6],
- ['Tonga', 0, 2, 6, 8],
- ['Cook', 4, 9, 7, 8],
- ];
- let location = 'On the bottom of the ocean';
- for (const island of islands) {
- if (pointInRectangle(x, y, island[1], island[2], island[3], island[4])) {
- location = island[0];
- }
- }
- return location;
- }
- for (let i = 0; i < input.length; i += 2) {
- const x = input[i];
- const y = input[i + 1];
- console.log(locate(x, y));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement