Created Container parent class. Introduced soem fancy bugs.
This commit is contained in:
26
Container.ts
Normal file
26
Container.ts
Normal 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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user