Code Monkey home page Code Monkey logo

reverse-a-string-using-a-stack-in-javascript's Introduction

Reverse a String with a Stack

For implementing the stack, I am using a class-based approach. In order to store the data in the stack, I am using the constructor method to create and initialize the stack. The data variable will hold elements to our stack.

I am using the following methods inside the stack:

  • push() - used to add an element to the stack;
  • pop() - used to remove and return the last element of the stack;
  • isEmpty() - used to check if the stack is empty; returns true or false.

In order to reverse a string, I created the reverseString function. The function takes one parameter, the string, and it returns the reversed string.

When running the function, each character from the string will be pushed to the stack. After that, each character (starting with the last character) from the stack will be popped out from the stack to a new string called reversed, until the stack is empty. Then, the function will return the reversed string.

reverse-a-string-using-a-stack-in-javascript's People

Contributors

alexandracaulea avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.