nowjs-core
Version:
NowCanDo Javascript Core [nowjs-core] is a library written by TypeScript code maintains under Apache 2.0 licence
81 lines (80 loc) • 1.77 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../linq/index");
const Collection_1 = require("./Collection");
const List_1 = require("./List");
class Stack {
constructor(enumerable) {
this.arr = [];
if (enumerable && enumerable[Symbol.iterator]) {
for (const x of enumerable) {
this.push(x);
}
}
}
contains(item) {
return (this.arr.findIndex(xx => {
return xx === item;
}) >= 0);
}
get size() {
return this.arr.length;
}
clear() {
this.arr = [];
return true;
}
push(...rest) {
if (rest instanceof Array) {
for (const xx of rest) {
this.arr.push(xx);
}
return true;
}
else {
this.arr.push(rest);
return true;
}
}
pop() {
return this.arr.pop();
}
peek() {
if (this.arr.length > 0)
return this.arr[0];
else
return null;
}
toArray() {
const array = [];
for (const xx of this) {
array.push(xx);
}
return array;
}
toCollection() {
return new Collection_1.Collection(this);
}
toList() {
return new List_1.List(this);
}
linq() {
return new index_1.Enumerable(this);
}
plinq() {
return new index_1.ParallelEnumerable(this);
}
[Symbol.iterator]() {
return this.arr[Symbol.iterator]();
}
clone() {
return new Stack(this);
}
toSet() {
return new Set(this);
}
isEmpty() {
return this.size === 0;
}
}
exports.Stack = Stack;