Git Product home page Git Product logo

algorithm_students's Introduction

Algorithm for students

A series of algorithms will test students on ways to solve basic/intermediate algorithm problems using vanilla javascript.

Getting Started

These instructions will help you get your javascript enviroment set up for testing your algorithms.

Prerequisites

Basic understanding of npm and javascript

Installing

You want to first git clone this repo

git clone https://github.com/Andyt-Nguyen/Algorithm_students.git

then you want to install all the dependicies in this repo

npm i

Writing your algorithms

There will be empty functions that will have an empty return statement along with a

basic prompt on the function's purpose.

/* 

    Problem 1:
    Prompt: Sort the array so that the even numbers(sorted by ascending order)
            are followed by the odd numbers in ascending order.
        
    Test cases: 
        (This only test some cases for you to get an idea. This does not reflect if your algo works for all test cases)
        (run `npm run test` to check if your alg passes the tests.)

        [ 366, 311, 142 ] return [ 142, 366, 311 ]
        [ 351, 85, 85 ] return [ 85, 85, 351 ]
        [ 145, 372, 83, 290 ] return [ 290, 372, 83, 145 ]

*/


 function sortEvenAndOdd(array) {
    //  Write code in here
    return;
} 

You will want to execute your code in the function that says '// Write code in here'

 function sortEvenAndOdd(array) {
    //  Write code in here
    return;
} 

Testing your functions

When your code is written you will have to run a command within your termial/command prompt to see if you have pass all the test cases.

You will run this command in your terminal/command prompt to execute if you have pass the series of tests

npm run test

Expected results

These test will have a series of inputs that it will test to see if you offically passes all the test and the function works as it is expected.

Example: A function that has passed all the test cases

  Testing Algorhthms
    Captalize the first letter in every word as well as lowercase every word
       Should Return 'I Like Turtles'
       Should Return 'David Likes To Eat Cookies When Nobody Is Watching'
       Should return You Are The Master At Javascript
       Should retrun Ieatfoodallday
    Return an array with no duplications in descending order
       Should return [33,22,11]
       Should return [ 44, 42, 12, 7, 5, 2 ]
       Should return  [ 3000, 528, 100, 92, 55, 49, 22, 4, 2, 1, 0 ]
       Should return ['cc','bb','aa']

Example: A test that has failed one of the test cases

  7) Testing Algorhthms
       Return an array with no duplications in descending order
         Should return ['cc','bb','aa']:

      AssertionError: expected [ 'aa', 'aa', 'bb', 'bb', 'cc', 'cc' ] to have the same members as [ 'cc', 'bb', 'aa' ]
      + expected - actual

       [
      +  "cc"
      +  "bb"
         "aa"
      -  "aa"
      -  "bb"
      -  "bb"
      -  "cc"
      -  "cc"
       ]
      
      at Context.it (test.js:46:20)

Isolating each function for testing

For each algorithm that you're going to solve its going to be hard to read what test cases you got wrong when all of the functions are laid out in front of you. Because of this you're going to be seeing a lot of red in your terminal. So a way to make sure your function is isoloated (by itself ) you can git checkout each branch to test your function by itself.

Steps to isoloate function within the terminal/command prompt

To see all of the available branches

git branch -a

Output:

  remotes/origin/HEAD -> origin/master
  remotes/origin/Problem2
  remotes/origin/Problem3
  remotes/origin/Problem4
  remotes/origin/Problem5
  ...

Checking into a branch

git checkout origin/Problem2

When checking into a new branch run inside your terminal/command prompt to download the dependencies

npm i

Output in the terminal in isolated enviroment. A lot of the tests will be skipped in order to test the alg problem you are trying to solve.

  Testing Algorhthms
    Return evens and odd numbers in descending order where the evens appear first in the array
      - Should return [8,6,0,7,5,1]
      - Should return [2,16,88,11,63,809]
      - Should return [2000,2012,5100,4323,7877,9093]
    Captalize the first letter in every word as well as lowercase every word
      1) Should Return 'I Like Turtles'
      2) Should Return 'David Likes To Eat Cookies When Nobody Is Watching'
      3) Should return You Are The Master At Javascript
      4) Should retrun Ieatfoodallday
    Return an array with no duplications in descending order
      - Should return [33,22,11]
      - Should return [ 44, 42, 12, 7, 5, 2 ]
      - Should return  [ 3000, 528, 100, 92, 55, 49, 22, 4, 2, 1, 0 ]
      - Should return ['cc','bb','aa']
    ...

Getting out of the remote branch.

git add .
git commit -m "message"
git checkout master

Note: Once you isolate your function to test if it works your progress will not be saved in the master branch so make sure to save your progress in the "master" branch.

Built With

  • Mocha -Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases

  • Chai - Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.

Authors

algorithm_students's People

Contributors

andyt-nguyen avatar

Watchers

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