Coder Social home page Coder Social logo

vue-ts-calculator's Introduction

VUE-TS-Calculator

A "simple" project that turned out to be a lot more in depth than I thought. This calculator mimics the functionality of the google search calculator.

Technologies

  • Vue.js 3
  • TypeScript
  • Tailwind CSS
  • Jest (Unit Tests)

Behind The Scenes

Parsing bedmas operations was the hardest part of this project. After the equation string is cleaned to a consistent format, the string is analyzed and turned into an array of Arrays. Each interior array represents the order of what needs to be calculated first in terms of bedmas. We take of advantage of resursive functions to go inside each array and equate them before equating the entire string together.

After bedmas, parsing the parenthesis was another difficult task that was made easy using recursion. Now, even brackets inside of brackets can be parsed into sub-arrays for preparation to equate using bedmas.

vue-ts-calculator's People

Contributors

ryandougc avatar

Watchers

James Cloos avatar  avatar

vue-ts-calculator's Issues

Jest tests not consistent with previous project location

Once I migrated the Jest tests from my TypeScript project into the Vue project, 3 of the Typescript tests failed. 2 Of them behaved in a way that was acceptable and still return the correct answer. However one of the tests doesn't account for bedmas correctly.

Inputting (1 + 1 * 2) into the calculator will return [ ["1", "+", "1", "", "2"] ] which doesn't use bedmas for equating. Instead it should be setting the equation to [ [ "1", "+", ["1", "", "2"] ] ]

After getting a total, the next input should replace it

After pressing equals, the total will show in the input bar. Currently, pressing a button to continue the equation will add on to the total. But it should replace the total, with the total being available as the ANS button

Input/output of the calculator won't show decimals

The textbox input that is used for I/O of the calculator does not show decimals. Even when passing a string of '1.666667' the calculator rounds it to showing "1".

My initial thought was that it was converting a number into a string and losing the decimal data. But now I convert the number into a string using the toFixed() equation and it still rounds the number.

Account for parsing brackets inside of brackets

No testing has been done for what happens when an equation is submitted with brackets inside of brackets. With the recursion set to be able to hand this, I have no idea if it will handle it properly and return the expected outcome since it hasn't been tested

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.