1 | const countries = { |
||
2 | 'Nigeria' : 'NG', |
||
3 | 'Ghana' : 'GH', |
||
4 | 'Kenya' : 'KE', |
||
5 | 'Uganda' : 'UG', |
||
6 | 'South Africa' : 'ZA' |
||
7 | } |
||
8 | |||
9 | const filterCountry = (country = null)=>{ |
||
10 | if(country == null || country == undefined){ |
||
0 ignored issues
–
show
Best Practice
introduced
by
![]() |
|||
11 | return 'NG'; |
||
12 | } |
||
13 | country = country.toUpperCase(); |
||
14 | |||
15 | if(country == 'NIGERIA'){ |
||
16 | return 'NG'; |
||
17 | } |
||
18 | |||
19 | if(country == 'GHANA'){ |
||
20 | return 'GH'; |
||
21 | } |
||
22 | |||
23 | if(country == 'KENYA'){ |
||
24 | return 'KE'; |
||
25 | } |
||
26 | |||
27 | if(country == 'UGANDA'){ |
||
28 | return 'UG'; |
||
29 | } |
||
30 | |||
31 | return country; |
||
32 | } |
||
33 | |||
34 | const randomNumber = (max)=> { |
||
35 | return Math.floor(Math.random() * max); |
||
36 | } |
||
37 | |||
38 | const isString = (string) =>{ |
||
39 | |||
40 | if (typeof string === 'string' || string instanceof String){ |
||
41 | return true; |
||
42 | } |
||
43 | |||
44 | return false; |
||
45 | } |
||
46 | |||
47 | |||
48 | module.exports = { |
||
49 | filterCountry, |
||
50 | randomNumber, |
||
51 | isString, |
||
52 | countries |
||
53 | }; |