Coder Social home page Coder Social logo

utility-js's Introduction

It’s time to get our hands dirty with Javascript. Now that you have heard about TDD, let see if we can transfer our learning to another world of Javascript.


Setup and Getting Started

We have created a dummy project for you. You’ll need nodejs pre installed to run this. Please check if it's installed by running which node on your terminal which should give you the path of node. If instead it comes up with a message like node not found then you should look online on how to install node. As such brew install node should work (if you're using Mac).


Running tests

After this, run the ./go.sh this should install any dependencies and then run the test. You should see one failing test and one passing test. Its good to get used to knowing how a passing/failing test looks with a particular tooling. Fix the test and move on to the next step.


About the assignment

  • In this assignment, we want you to understand that loops are an imperative way of programming. Usual use cases of loops can be classified as
    • Converting one collection to another collection - Typical use of map, return type is collection
    • Getting a subset of a collection - Typical use of filter, return type is collection.
    • Converting collection to a value - Typical use of reduce, return type maybe not a collection.

Keep in mind

  • We want you to TDD and use Javascript to implement these functions.
  • Avoid using loops in your implementation as much as possible.
    • Recursion is your friend
    • You can reuse a function that you have written yourself
  • Make sure you have small commits (after each passing test and refactoring as necessary)

Functions to implement

  • head - returns first element
    • e.g. head([1,2,3]) should be 1
    • e.g head([]) should be null or undefined
  • tail - returns everything except first element
    • e.g. tail([1,2,3]) should be [2,3]
    • e.g tail([]) should be []
  • map
    • e.g map([], cube) should give []
    • e.g map([1,2,3], identity) should give [1,2,3]
    • e.g.map([1,2,3], cube) should give [1,8,27]
    • e.g. map([a{x : 10}],someObject => someObject.x + 1) -> [11]
      • where identity and cube are functions
  • filter
    • e.g filter([], x => true) should give []
    • e.g. filter([1,2,3],x => true) should give [1,2,3]
    • e.g. filter([1,2,3],x => false) should give []
    • e.g. filter([1,2,3],x => x > 1) should give [2,3]
    • e.g. filter(['a','B','c','D'], filterUpperCase) should be [B,D]
  • reduce
    • e.g. reduce([],(x,y)=>x+y) should be undefined
    • e.g. reduce([],v(x,y)=>x+y,10) should be 10
    • e.g. reduce(['a','b','c'],(x,y)=>x+y) should be abc
    • e.g. reduce(['a','b','c'],(x,y)=>x+y,’z’), should be zabc
  • max
    • e.g. max([1,2,3,4]) should be 4
  • min
    • same as above... return 1

utility-js's People

Contributors

venu-prasanna 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.