VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
Stacks (Data Structure) - Beau teaches JavaScript

Stacks (Data Structure) - Beau teaches JavaScript

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
Stacks are a programming data structure. Learn how they work in JavaScript. Code: - http://codepen.io/beaucarnes/pen/yMBGbR?editors=0012 More information: - http://radar.oreilly.com/2014/03/stacks-in-javascript.html -Beau Carnes on
Date: 2022-03-14

Comments and reviews: 6


function isPalindrome(str) -
for (let i=0; i < str.length - i; i++) -
if(str[i]!==str[str.length-1-i]) return false
-
return true
-
You can access string with [i]ndexes.
You don't need to use additional variables (except iterator).
You don't need to modify the original string or split it into an array and modify it (with pop and especially shift).
You may add a length>0 check if you feel like an empty string is not a palindrome.
Comments are welcome.
UPD. I forgot to mention that it will work with arrays too.

reply

Great video! One question,
Even though pop() removes the top element from the stack, the storage array still preservers the same size (for example, say we've pushed onto storage [10,20,40], then popped the stack, we get [10,20,], yet when doing console.log(stack.storage.length), we still get 3, not 2.

reply

Beau, I love your videos, but please be more careful. There are a bunch of mistakes in almost every video you make. You can easily edit them or even redo them. A stack is not a First In First Out, that's a queue. I don't mind small mistakes, but if they are perennial they become annoying.
reply

One Question; what if we peek on empty stack here ? Shouldn't we check in peek function whether count is 0 or not ?
Is it something like it should return -1 in case of empty stack ? But here storage object don't have -1 as a key... suggestions would be appreciated.

reply

function isPalindrone(str) -
var stack = str.split('')
var isPalindrone = true
while(isPalindrone === true && stack.length > 1) -
isPalindrone = stack.shift() === stack.pop()
-
return isPalindrone
-

reply

Excellent tutorial. but, You mentioned that, Stack is FIFO-First in First Out data structure. Stack is Not FIFO. Queue is FIFO. Stack is FILO or LIFO.
reply
Add a review, comment






Other channel videos