mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Remove Duplicates from Pokemon Pokedex entries
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "112.2.3",
|
||||
"version": "112.2.4",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
|
||||
@@ -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(' ');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user