Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- class Point {
- constructor(x,y) {
- this.x = x
- this.y = y
- }
- toString() {
- return `Point(${this.x},${this.y})`
- }
- }
- class PointSet {
- constructor() {
- this.map = new Map()
- this[Symbol.iterator] = this.values
- }
- add(item) {
- this.map.set(item.toString(), item)
- }
- get values() {
- return this.map.values()
- }
- get size() {
- return this.map.size
- }
- }
- function random() {
- return Math.floor(Math.random()*10)
- }
- let coords = new PointSet()
- while (coords.size < 100) {
- coords.add(new Point(random(),random()))
- }
- console.log(coords.values)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement