Skip to content

Commit

Permalink
Add a sort to the data before creating the custom array
Browse files Browse the repository at this point in the history
  • Loading branch information
LucianoGanga committed Dec 27, 2019
1 parent 9ad8a93 commit e14f128
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ module.exports = {
data = data.filter(filter)
}

if (sortBy && fields[sortBy]) {
// ignore upper and lowercase
const collator = new Intl.Collator([], {sensitivity:'accent'})
data.sort((a, b) => collator.compare(a[sortBy], b[sortBy]))
}

data.forEach(countryData => {
let collectionObject = {}
for (const field in fields) {
Expand All @@ -52,12 +58,6 @@ module.exports = {
finalCollection.push(collectionObject)
})

if (sortBy && fields[sortBy]) {
// ignore upper and lowercase
const collator = new Intl.Collator([], {sensitivity:'accent'})
finalCollection.sort((a, b) => collator.compare(a[sortBy], b[sortBy]))
}

return finalCollection
},
/**
Expand Down

0 comments on commit e14f128

Please sign in to comment.