Coder Social home page Coder Social logo

digitadd's Introduction

Problem description: Base 10 Math with Strings

Goal

Create a function(s) to implement the following signatures. The implementation must adhere to only string inputs and string outputs. In addition, all math operations must be no larger than one digit (Base10) + one digit (Base10). Thus the largest sum possible internally must be < 20.

Signatures

add(a, b) -> (sum) add(a, b, c, ...) -> sum

Expectations

Implement a testing strategy to verify your work.

Examples

add('1', '3') -> '4' add('2', '8') -> '10' add('12', '9') -> '21' add('19999', '22') -> '20021'

Extra Credit

How might you handle negative numbers? Consider ways you might implement this part of our Base 10 Math with Strings. This extra credit is primarily a thought exercise, no code need be implemented.

Solution

Approach

There are two ways to approach this.

 1345       1|3|4|5|                  1|3|4|5|
  832         8|3|2|           OR   +   8|3|2| 
  437         4|3|7|                  --------
-----       --------              R|E|S|U|L|T|
                                    +  |4|3|7|
                                      --------

Approaching the problem using the sum by row, then column appears easier from an algorithmic perspective. The reason being that, in that case carry-over, will every only be 1. Since the largest numbers (9+9) = 18. Store digit = 8, carry-over digit = 1. So, going to approach it that way to begin with.

Runing

The solution is written in JavaScript and should be running using NodeJS. To run all tests, install NodeJS in your OS of choice. Then, simply run using: node solution.js

digitadd's People

Contributors

clsk avatar

Watchers

James Cloos avatar  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.