Code Monkey home page Code Monkey logo

rise-challenge's Introduction

How to run

Ensure you have node installed (instructions can be found at nodejs.dev).

At the terminal, cd into the directory challenge.js is in and run node challenge.js.

Overview

I have created an array named sampleQuestions of 10 sample questions in the specified format, i.e. "What is dd + dd?"

The function getAnswer accepts a question number, finds the equation in the string using a regex (equationRegex) and assigns it to the variable equationStr. I then split the two two-digit numbers into their own variables, num1 and num2, and return the sum. I've avoided using the built in function eval(), as it is generally bad practice to utilise.

logQuestions is composed of a simple for loop which assigns an getAnswer[i] value to the variable answer and calls console.log() in the specified format using a string literal.

I've split the code into two functions, seperating the logic of evaluating the question and improving readability.

getAnswer is not strictly a pure function as it calls an external array. I've done this more for readablity, but the arr could easily be inside of the getAnswer function.

I've attempted to give meaningful variable and function names for the benefit of those reviewing it.

There is some potential bugs that could arise. To me, the two most apparent would be getAnswer() being passed an argument that is not a valid index number of sampleQuestions, and equationStr not matching a sample question. Both can be easily handled with if/else statements.# rise-challenge

rise-challenge's People

Contributors

danmolloy avatar

Watchers

 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.