class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
// Getters
getX() {
return this.x;
}
getY() {
return this.y;
}
// toString for key representation
toString() {
return `(${this.x}, ${this.y})`;
}
// Custom key for Map (since JS Maps use reference equality for objects)
key() {
return `${this.x},${this.y}`;
}
}
// Simulate Map<Point, String> using string keys
const map = new Map();
map.set(new Point(2, 7).key(), "A");
map.set(new Point(3, 6).key(), "B");
map.set(new Point(0, 0).key(), "C");
// Print x and y separately
for (const [keyStr, value] of map.entries()) {
const [x, y] = keyStr.split(',').map(Number);
console.log(`x: ${x}, y: ${y} => ${value}`);
}
/*
run:
x: 2, y: 7 => A
x: 3, y: 6 => B
x: 0, y: 0 => C
*/