Last active
November 10, 2019 08:36
-
-
Save ilopX/896dbc50ccf765442e333af139e55479 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createBird() { | |
let distance = 0 | |
let self = { | |
fly(A = 1) { | |
distance += A | |
return self | |
}, | |
getDistance() { | |
return distance | |
}, | |
compareWith(bird) { | |
return bird.getDistance() > distance | |
? 'Another bird win' | |
: 'I win' | |
} | |
} | |
return self | |
} | |
const bird1 = createBird(); | |
const bird2 = createBird(); | |
const bird3 = createBird(); | |
bird1.fly() | |
bird1.fly() | |
assert(bird1.getDistance()).toBe(2) | |
bird2.fly().fly().fly() | |
assert(bird2.getDistance()).toBe(3) | |
bird2.fly(3) | |
assert(bird2.getDistance()).toBe(6) | |
bird1.fly(2).fly().fly(1) | |
assert(bird1.getDistance()).toBe(6) | |
bird1.fly(3) | |
assert(bird1.getDistance()).toBe(9) | |
bird3.fly(2) | |
assert(bird2.compareWith(bird3)).toBe('I win'); | |
assert(bird1.compareWith(bird3)).toBe('I win'); | |
assert(bird3.compareWith(bird1)).toBe('Another bird win'); | |
bird3.fly(50) | |
assert(bird1.compareWith(bird3)).toBe('Another bird win'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment