-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
38 lines (33 loc) · 996 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { getTypeWeaknesses } from './index'
import { noEffect, notVeryEffective, superEffective, ultra } from './effectiveness'
const abilityEffectiveness = (abilityType, targetType) => {
switch (getTypeWeaknesses(...targetType)[abilityType]) {
case noEffect: return 'It has no effect...'
case notVeryEffective: return 'It\'s not very effective...'
case superEffective: case ultra: return 'It\'s super effective!'
default: return ''
}
}
const attack = pokemon => target => ability => {
return `
${pokemon.name} used ${ability.name}!
💥
${abilityEffectiveness(ability.type, target.type)}
`
}
const pikachu = {
name: 'Pikachu',
type: 'electric',
abilities: {
thunderbolt: {
name: 'Thunderbolt',
type: 'electric'
}
},
attack: target => ability => attack(pikachu)(target)(pikachu.abilities[ability])
}
const gyarados = {
name: 'Gyrados',
type: ['water', 'flying']
}
console.log(pikachu.attack(gyarados)('thunderbolt'))