stack in javascript

Solutions on MaxInterview for stack in javascript by the best coders in the world

showing results for - "stack in javascript"
Anthony
10 Jan 2020
1class Stack{
2   constructor() 
3    { 
4        this.items = []; 
5    } 
6   
7    push(element) 
8   { 
9    // push element into the items 
10    this.items.push(element); 
11    }
12  
13    pop() 
14    { 
15    if (this.items.length == 0) 
16        return "Underflow"; 
17    return this.items.pop(); 
18    } 
19  
20    peek() 
21	{ 
22    	return this.items[this.items.length - 1]; 
23	} 
24  
25    printStack() 
26    { 
27    	var str = ""; 
28    	for (var i = 0; i < this.items.length; i++) 
29        	str += this.items[i] + " "; 
30    	return str; 
31    } 
32
33}
Kris
27 Nov 2019
1function Stack() {
2  var collection = [];
3  this.print = function() {
4    console.log(collection);
5  };
6  this.push = function(val) {
7    return collection.push(val);
8  };
9  this.pop = function() {
10    return collection.pop();
11  };
12  this.peek = function() {
13    return collection[collection.length - 1];
14  };
15  this.isEmpty = function() {
16    return collection.length === 0;
17  };
18  this.clear = function() {
19    collection.length = 0;
20  };
21}
22
queries leading to this page
how to create a stack in jsjavascript array stackhow to define a stack in javascriptstack code in jsuse stack in jswhat is javascript stackstacking elements in javascriptstack methods javascripthow to create stack in javascriptcreate a stack javascriptjavascript java stackstack funtions jsstack in jsmake stack javascripthow to create a stack in javascriptimplement stack javascriptstack example in javascripthow to implement a stack in javascriptstack with array javascriptcreating a stack in javascriptstack functions javascriptstack implementation using javascriptwhat is new stack in javascriptstack example jscan you stack methods in javascriptjavascript stack implementationstack in javascript demodoes javascript have stackjs function stack examplestack program in javascriptwhat is stack in javascriptwhat is stack in jswhat does stack means in javascript 3fstack in array jsall javascript stackwhere is the stack jsstack using javascripthow to declare stack in javascripthow does the stack work javascriptstack arrays in javascriptstack method in javascriptstack using array jsfull javascript stackjavscript stackwhat is a stack javascriptcreate stack in javascripthow to use stack in javascriptstack implementation javascriptstack meaning javascriptcreate stack in jsstack methods in javascriptjavastript stackstack with javascriptstack jsimplement a stack in jsis there a stack in jsjavascript stack functionsto how create stack in javscriptwhat is a stack in javascriptjavascript stack stack in jsstack implementation jsstack implementation in javascriptstack javascript examplestack using jsstack with jsstack array in javascriptwhat is call stack in javascript 3fhow to implement a stack javascriptstack explain using javascriptstacking elements jsjavascript stack examplecreating stack in js stack based javascriptstack in javascriptstack in java scripfunction stack javascriptcreating a stack in jswhat is stack jscreate a stack in javascripthow to implement stack in javascriptjs stackwhait is stack in javascriptcreate javascript stackstack with plain javascriptcreate a stack in jsimplement stack in javascriptmaking stack javascriptstack in javascript w3schoolsjs function stack how to make a stack in javascriptstack jshow to use stack in jsstack methodds in javascriptjavascript how to implement a javascript stackprogram stack javascriptstack array javascriptstack functions jsis there stack in javascriptstack javascript arrayjavascript stackhow to make a stack in javscriptstack javascriptstack for jsimplement stack in jsimplement stack using javascriptstack array jsjavascript stack stackstack in javascript