Skip to content

Instantly share code, notes, and snippets.

@buymed-hoangpham
Created October 1, 2022 09:50
Show Gist options
  • Save buymed-hoangpham/de05f174a744b6666c1daa9caa47f3b2 to your computer and use it in GitHub Desktop.
Save buymed-hoangpham/de05f174a744b6666c1daa9caa47f3b2 to your computer and use it in GitHub Desktop.
exercise
// 1 type Point = {x: number, y: number};
type Point = {x: number, y: number}
// 2 let coors: Point[] = []
let coors: Point[] = []
// 3 write a function in order to generate default Point => {x: 0, y: 0} generateOriginalPoint()
const generateOriginalPoint = (): Point => ({x: 0, y: 0})
// 4 write a function in order to generate a random Point => {x: random, y: random} generateRandomPoint()
const generateRandomPoint = ():Point => ({x: Math.random() * 101, y: Math.random() * 101})
// 5 loops push 100 default Point and 100 randomPoint
const result = (): Point[] => {
for(let i = 0; i < 100; i++) {
coors.push(generateOriginalPoint())
coors.push(generateRandomPoint())
}
return coors;
}
console.log(result())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment