alapa
Version:
A cutting-edge web development framework designed to revolutionize the way developers build modern web applications.
41 lines (40 loc) • 1.1 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.List = void 0;
/**
* A generic list class that extends the TypeScript Array class,
* allowing storage of items of type V in an array-like structure.
*
* @template V - The type of items in the list.
*/
class List extends Array {
/**
* Creates a new List with optional initial items.
*
* @param initialItems - An optional array of initial items.
*/
constructor(...initialItems) {
super(...initialItems);
}
/**
* Removes an item from the list by element.
*
* @param element - The element to remove.
* @returns The updated list after removal.
*/
remove(element) {
const index = this.findIndex((item) => item === element);
if (index !== -1) {
// Check if the index is valid and remove the item
this.splice(index, 1);
}
return this; // Return the updated list
}
/**
* Clears all items from the list.
*/
clear() {
this.length = 0;
}
}
exports.List = List;
;