-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
25 lines (24 loc) · 873 Bytes
/
index.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
var countries = require('./lib/countries.json')
module.exports = {
all: function() {
var currencies = [];
countries.map(function (country) {
currencies.push(country.symbol)
})
return currencies;
},
symbol: function (name) {
name = name.toLowerCase().trim();
var currencySymbol;
countries.map(function (country) {
var countryArray = country.currency.split(" ");
var currencyName = countryArray.pop().toLowerCase().trim();
var currencyAbbr = country.abbreviation.toLowerCase();
var countryName = countryArray.join(" ").toLowerCase().trim();
if (name === currencyName || name === countryName || name === currencyAbbr){
currencySymbol = country.symbol;
}
})
return currencySymbol;
},
};