Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. function normalize({x, y}) {
  2. const nx = x / Math.abs(x)
  3. const ny = y / Math.abs(x)
  4. return nx + '|' + ny
  5. }
  6.  
  7. /*
  8. console.log(normalize({x: 1, y: 2}))
  9. console.log(normalize({x: 2, y: 4}))
  10. console.log(normalize({x: -2, y: 4}))
  11. console.log(normalize({x: 2, y: -4}))
  12. console.log(normalize({x: -2, y: -4}))
  13. console.log(normalize({x: -1, y: -2}))
  14. console.log(normalize({x: -1, y: -4}))
  15. */
  16.  
  17. function solution(A) {
  18. const nA = A.map(i => normalize(i))
  19. const uniqueA = [...new Set(nA)]
  20. return uniqueA.length
  21. }
  22.  
  23. /*
  24. console.log(solution([{x:1, y:1}, {x:2, y:2}])) // 1
  25. console.log(solution([{x:-1, y:1}, {x:-2, y:2}])) // 1
  26. console.log(solution([{x:-1, y:-1}, {x:-2, y:-2}])) // 1
  27. console.log(solution([{x:-1, y:-1}, {x:2, y:2}])) // 2
  28. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement