Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. 'use strict'
  2. class Point {
  3. constructor(x,y) {
  4. this.x = x
  5. this.y = y
  6. }
  7. toString() {
  8. return `Point(${this.x},${this.y})`
  9. }
  10. }
  11.  
  12. class PointSet {
  13.  
  14. constructor() {
  15. this.map = new Map()
  16. this[Symbol.iterator] = this.values
  17. }
  18.  
  19. add(item) {
  20. this.map.set(item.toString(), item)
  21. }
  22.  
  23. get values() {
  24. return this.map.values()
  25. }
  26.  
  27. get size() {
  28. return this.map.size
  29. }
  30. }
  31.  
  32. function random() {
  33. return Math.floor(Math.random()*10)
  34. }
  35.  
  36. let coords = new PointSet()
  37.  
  38. while (coords.size < 100) {
  39. coords.add(new Point(random(),random()))
  40. }
  41.  
  42. console.log(coords.values)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement