Render threadables

This commit is contained in:
Jose Farias
2024-10-23 14:12:28 -06:00
parent 35a31e3203
commit 5221807847
18 changed files with 84 additions and 15 deletions
@@ -0,0 +1,17 @@
Array.prototype.toSentence = function() {
const length = this.length
switch (length) {
case 0:
return ""
case 1:
return `${this[0]}.`
case 2:
return `${this[0]} and ${this[1]}.`
default:
return this.map((item, index) => {
const isLast = index === length - 1
return isLast ? `and ${item}.` : item
}).join(", ")
}
}