diff --git a/package.json b/package.json index 299b8736..d4605634 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "112.2.3", + "version": "112.2.4", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": { diff --git a/structures/pokemon/Pokemon.js b/structures/pokemon/Pokemon.js index 3a291317..f58bcadd 100644 --- a/structures/pokemon/Pokemon.js +++ b/structures/pokemon/Pokemon.js @@ -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}`; } diff --git a/util/Util.js b/util/Util.js index 089effeb..587099f0 100644 --- a/util/Util.js +++ b/util/Util.js @@ -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(' '); }