Created Container parent class. Introduced soem fancy bugs.

This commit is contained in:
2021-05-02 14:44:59 -07:00
parent fbf841b551
commit 8d854945e1
6 changed files with 43 additions and 31 deletions

26
Container.ts Normal file
View File

@ -0,0 +1,26 @@
import type { Item } from "./data/data.ts";
export default class Container {
protected items: Item[];
constructor(items: Item[]) {
this.items = items;
}
description(items: Item[]): string {
const vowels = ["a", "e", "i", "o", "u"];
const description = items
.map(({ name }, i) => {
let anItem = `${vowels.includes(name[0]) ? "an" : "a"} ${name}`;
if (i + 1 === items.length) {
anItem = `and ${anItem}`;
}
return anItem;
})
.join(", ");
return description;
}
}