@barchart/common-js
Version:
Library of common JavaScript utilities
103 lines (97 loc) • 2.51 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var LinkedList_exports = {};
__export(LinkedList_exports, {
default: () => LinkedList
});
module.exports = __toCommonJS(LinkedList_exports);
class LinkedList {
#value;
#next;
/**
* @param {*} value - The value of current node.
*/
constructor(value) {
this.#value = value;
this.#next = null;
}
/**
* Returns the value associated with the current node.
*
* @public
* @returns {*}
*/
getValue() {
return this.#value;
}
/**
* Returns the next node, if it exists; otherwise a null value is returned.
*
* @public
* @returns {LinkedList|null}
*/
getNext() {
return this.#next;
}
/**
* Returns true, if the node is the last one in the list.
*
* @public
* @returns {boolean}
*/
getIsTail() {
return this.#next === null;
}
/**
* Adds (or inserts) a value after the current node and returns
* the newly added node.
*
* @public
* @param {*} value
* @returns {LinkedList}
*/
insert(value) {
const next = new LinkedList(value);
if (this.#next) {
next.#next = this.#next;
}
this.#next = next;
return next;
}
/**
* Returns a string representation.
*
* @public
* @returns {string}
*/
toString() {
return "[LinkedList]";
}
}
{
const cjsExports = module.exports;
const cjsDefaultExport = cjsExports && cjsExports.__esModule ? cjsExports.default : cjsExports;
if (cjsDefaultExport && (typeof cjsDefaultExport === 'function' || typeof cjsDefaultExport === 'object')) {
Object.keys(cjsExports).forEach((key) => {
if (key !== 'default' && key !== '__esModule') {
cjsDefaultExport[key] = cjsExports[key];
}
});
}
module.exports = cjsDefaultExport;
}