Remove Duplicates from Pokemon Pokedex entries

This commit is contained in:
Dragon Fire
2020-03-08 11:16:26 -04:00
parent e0d131f394
commit 0f3eb4939e
3 changed files with 15 additions and 3 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "112.2.3",
"version": "112.2.4",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
+4 -2
View File
@@ -1,10 +1,12 @@
const { removeDuplicates } = require('../../util/Util');
module.exports = class Pokemon {
constructor(data) {
this.id = data.id;
this.name = data.names.find(entry => entry.language.name === 'en').name;
this.entries = data.flavor_text_entries
this.entries = removeDuplicates(data.flavor_text_entries
.filter(entry => entry.language.name === 'en')
.map(entry => entry.flavor_text.replace(/\n|\f|\r/g, ' '));
.map(entry => entry.flavor_text.replace(/\n|\f|\r/g, ' ')));
this.names = data.names.map(entry => ({ name: entry.name, language: entry.language.name }));
this.genus = `The ${data.genera.filter(entry => entry.language.name === 'en')[0].genus}`;
}
+10
View File
@@ -40,6 +40,16 @@ module.exports = class Util {
return arr;
}
static removeDuplicates(arr) {
if (arr.length === 0 || arr.length === 1) return arr;
const newArr = [];
for (let i = 0; i < arr.length; i++) {
if (newArr.includes(arr[i])) continue;
newArr.push(arr[i]);
}
return newArr;
}
static firstUpperCase(text, split = ' ') {
return text.split(split).map(word => `${word.charAt(0).toUpperCase()}${word.slice(1)}`).join(' ');
}