Skip to content

Commit

Permalink
feature(lga's): refactor lga function
Browse files Browse the repository at this point in the history
Instead of using the Map function to iterate over the states
Array.find() should be used as find() terminates when the value is found
over a map which iterates over all the objects in the array.
  • Loading branch information
seyi-adeleke committed Jan 22, 2018
1 parent c4fcc8b commit e5fbda3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
node_modules/
.idea/
20 changes: 11 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var statesAndLocalGov = require('./src/statesAndLocalGov.json')
var statesAndLocalGov = require('./src/statesAndLocalGov.json');

module.exports = {
all: function() {
Expand All @@ -8,23 +8,25 @@ module.exports = {
var naijaStates = [];
statesAndLocalGov.map(function (nigeriaStates){
return naijaStates.push(nigeriaStates.state)
})
});
return naijaStates;
},
lgas: function (state) {
state = state.toLowerCase().trim();
if(!state || state == ""){
var stateLocalGov;

if(!state || state.toLowerCase().trim() === ''){
throw new Error('Invalid Nigeria State');
}
state = state.toLowerCase().trim();

if (state === 'fct' || state === 'f.c.t' || state === 'abuja' || state === 'f c t'){
state = 'Federal Capital Territory'
}
var stateLocalGov;
statesAndLocalGov.map(function (nigeriaStates) {
statesAndLocalGov.find(function (nigeriaStates) {
if (nigeriaStates.state.toLowerCase() === state.toLowerCase().trim()){
return stateLocalGov = nigeriaStates.lgas;
return stateLocalGov = nigeriaStates.lgas;
}
})
});
return stateLocalGov;
}
};
};

0 comments on commit e5fbda3

Please sign in to comment.