replace structural loop with reduce

This commit is contained in:
KDSBrowne 2018-05-28 07:24:03 -07:00
parent d0660e6699
commit aa5deedbc9

View File

@ -25,20 +25,19 @@ WebApp.connectHandlers.use('/locale', (req, res) => {
const browserLocale = req.query.locale.split(/[-_]/g); const browserLocale = req.query.locale.split(/[-_]/g);
const localeList = [fallback]; const localeList = [fallback];
let getAvailableLocales = fs.readdirSync('assets/app/locales'); const getAvailableLocales = fs.readdirSync('assets/app/locales');
let regionDefault = null; let regionDefault = null;
const usableLocales = []; const usableLocales = [];
getAvailableLocales = getAvailableLocales getAvailableLocales
.map(file => file.replace('.json', '')) .map(file => file.replace('.json', ''))
.map(locale => ( .map(locale => (
locale locale
)); ))
.reduce((i, locale) => {
for (let i = 0; i < getAvailableLocales.length; i += 1) { if (locale === browserLocale[0]) regionDefault = locale;
if (getAvailableLocales[i] === browserLocale[0]) regionDefault = getAvailableLocales[i]; if (locale.match(browserLocale[0])) usableLocales.push(locale);
if (getAvailableLocales[i].match(browserLocale[0])) usableLocales.push(getAvailableLocales[i]); }, 0);
}
if (regionDefault) localeList.push(regionDefault); if (regionDefault) localeList.push(regionDefault);
if (!regionDefault && usableLocales[0]) localeList.push(usableLocales[0]); if (!regionDefault && usableLocales[0]) localeList.push(usableLocales[0]);