UNPKG

another-linked-list

Version:
2 lines 2.84 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("linked-list",[],t):"object"==typeof exports?exports["linked-list"]=t():e["linked-list"]=t()}("undefined"!=typeof self?self:this,(function(){return(()=>{"use strict";var e={462:(e,t,n)=>{function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}n.d(t,{default:()=>l});var r=function(){function e(t,n){void 0===n&&(n=null),function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.value=t,this.next=n}var t,n;return t=e,(n=[{key:"toString",value:function(e){return e?e(this.value):""+this.value}}])&&i(t.prototype,n),e}();function a(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}const l=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.head=null,this.tail=null}var t,n;return t=e,(n=[{key:"prepend",value:function(e){var t=new r(e,this.head);return this.head=t,this.tail||(this.tail=t),this}},{key:"append",value:function(e){var t=new r(e);return this.head?(this.tail.next=t,this.tail=t,this):(this.head=t,this.tail=t,this)}},{key:"delete",value:function(e){if(!this.head)return null;for(var t=null;this.head&&this.head.value===e;)t=this.head,this.head=this.head.next;var n=this.head;if(null!==n)for(;n.next;)n.next.value===e?(t=n.next,n.next=n.next.next):n=n.next;return this.tail.value===e&&(this.tail=n),t}},{key:"deleteTail",value:function(){var e=this.tail;if(this.head===this.tail)return this.head=null,this.tail=null,e;for(var t=this.head;t.next;)t.next.next?t=t.next:t.next=null;return this.tail=t,e}},{key:"deleteHead",value:function(){if(!this.head)return null;var e=this.head;return this.head.next?this.head=this.head.next:(this.head=null,this.tail=null),e}},{key:"find",value:function(e){var t=e.value,n=void 0===t?void 0:t,i=e.callback,r=void 0===i?void 0:i;if(!this.head)return null;for(var a=this.head;a;){if(r&&r(a.value))return a;if(void 0!==n&&a.value===n)return a;a=a.next}return null}},{key:"toArray",value:function(){for(var e=[],t=this.head;t;)e.push(t),t=t.next;return e}},{key:"toString",value:function(e){return this.toArray().map((function(t){return t.toString(e)})).toString()}}])&&a(t.prototype,n),e}()}},t={};function n(i){if(t[i])return t[i].exports;var r=t[i]={exports:{}};return e[i](r,r.exports,n),r.exports}return n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n(462)})().default})); //# sourceMappingURL=linked-list.min.js.map