@dsinjs/linked-list
Version:
Linked List for your DS in JS
1 lines • 5.59 kB
JavaScript
!function r(i,o,s){function l(e,t){if(!o[e]){if(!i[e]){var n="function"==typeof require&&require;if(!t&&n)return n(e,!0);if(a)return a(e,!0);throw(n=new Error("Cannot find module '"+e+"'")).code="MODULE_NOT_FOUND",n}n=o[e]={exports:{}},i[e][0].call(n.exports,function(t){return l(i[e][1][t]||t)},n,n.exports,r,i,o,s)}return o[e].exports}for(var a="function"==typeof require&&require,t=0;t<s.length;t++)l(s[t]);return l}({1:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=t("./linked-list-element");Object.defineProperty(n,"LinkedListElement",{enumerable:!0,get:function(){return r.LinkedListElement}});var i=t("./linked-list-main");Object.defineProperty(n,"LinkedList",{enumerable:!0,get:function(){return i.LinkedList}})},{"./linked-list-element":2,"./linked-list-main":3}],2:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.LinkedListElement=void 0;var r=(i.prototype.toJSON=function(){var t=this.data;return{data:"function"==typeof t.toJSON?t.toJSON():t,next:null!==this.next?this.next.toJSON():null}},i.prototype.toString=function(){var t=this.data;return("function"==typeof t.toString?t.toString():String(t))+(null!==this.next?this.next.toString():"")},i);function i(t,e){void 0===e&&(e=null),this.next=null,this.data=t,this.next=e}n.LinkedListElement=r,void 0!==e&&(e.exports={LinkedListElement:r}),"undefined"!=typeof window&&(window.DSinJS=window.DSinJS||{},window.DSinJS.LinkedListElement=r)},{}],3:[function(t,e,n){"use strict";var a=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(n,"__esModule",{value:!0}),n.LinkedList=void 0;var u=t("./linked-list-element");"undefined"!=typeof window&&"undefined"==typeof Symbol&&((r=window).Symbol={},r.Symbol.iterator="==iterator==");var r=(Object.defineProperty(o.prototype,"length",{get:function(){return this._length},enumerable:!1,configurable:!0}),o.prototype.insert=function(t){return t instanceof Array?t[0]instanceof u.LinkedListElement?this._insertLLElemArray(t):this._InsertRawTypeItemArray(t):t instanceof u.LinkedListElement?this._insertLLElem(t):this._InsertRawTypeItem(t)},o.prototype._InsertRawTypeItem=function(t){for(var e=this._start,n=e;null!==e;)e=(n=e).next;return n.next=new u.LinkedListElement(t),this._length++,n.next},o.prototype._InsertRawTypeItemArray=function(t){var e,n,r=new u.LinkedListElement(t[0]),i=r;t.splice(0,1);try{for(var o=a(t),s=o.next();!s.done;s=o.next()){var l=s.value,l=new u.LinkedListElement(l);i.next=l,i=i.next,this._length++}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return this._insertLLElem(r)},o.prototype._insertLLElem=function(t){for(var e=this._start,n=e;null!==e;)e=(n=e).next;return n.next=t,this._length++,n.next},o.prototype._insertLLElemArray=function(t){var e,n,r=t[0],i=r;t.splice(0,1);try{for(var o=a(t),s=o.next();!s.done;s=o.next()){var l=s.value;i.next=l,i=i.next,this._length++}}catch(t){e={error:t}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return this._insertLLElem(r)},o.prototype.push=function(t){return this.insert(t)},o.prototype.delete=function(t){for(var e=this._start,n=this._start;null!==e&&t!==e.data;)e=(n=e).next;return n&&e&&(n.next=e.next,e.next=null,this._length--),e},o.prototype.pop=function(){for(var t=this._start,e=this._start;null!==t.next;)t=(e=t).next;return e.next=null,t===this._start?null:(this._length--,t)},o.prototype.has=function(t){for(var e=this._start;null!==e;){if(e.data===t)return!0;e=e.next}return!1},o.prototype.traverse=function(t){for(var e=this._start,n=0;null!==e;){if(!t(e,n))break;e=e.next,n++}},o.prototype.entries=function(){return this.toArray().entries()},o.prototype[Symbol.iterator]=function(){return this.toArray()[Symbol.iterator]()},o.prototype.each=function(t){return this.traverse(t)},o.prototype.forEach=function(t){return this.traverse(t)},o.prototype.map=function(t){for(var e=new o(t(this._start.data)),n=this._start.next,r=e._start;null!==n;)r.next=new u.LinkedListElement(t(n.data)),e._length++,n=n.next,r=r.next;return e},o.prototype.filter=function(t){for(var e=null,n=this._start;null===e&&n;)t(n.data)&&(e=n.data),n=n.next;if(null===e)return null;for(var r=new o(e),i=r._start;null!=n;)t(n.data)&&(i.next=new u.LinkedListElement(n.data),r._length++),n=n.next;return r},o.prototype.reduce=function(n,t){var r=this;void 0===t&&(t=0);var i=t;return this.traverse(function(t,e){return i=n(i,t.data,e,r),!0}),i},o.prototype.get=function(t){for(var e=this._start,n=0,r=null;null!==e;){if(t===n){r=e.data;break}e=e.next,n++}return r},o.prototype.toString=function(){return this._start.toString()},o.prototype.toJSON=function(){return this._start.toJSON()},o.prototype.toArray=function(){for(var t=[],e=this._start;null!==e;)t.push(e.data),e=e.next;return t},o.fromArray=function(t){for(var e=1,n=new o(t[0]),r=n._start;e!==t.length;)r.next=new u.LinkedListElement(t[e]),r=r.next,e++,n._length++;return n},o);function o(t){this._length=1,this._start=t,this._start instanceof u.LinkedListElement||(this._start=new u.LinkedListElement(this._start))}n.LinkedList=r,void 0!==e&&(e.exports={LinkedListElement:u.LinkedListElement,LinkedList:r}),"undefined"!=typeof window&&(window.DSinJS=window.DSinJS||{},window.DSinJS.LinkedList=r)},{"./linked-list-element":2}]},{},[1]);