Skip to content

Instantly share code, notes, and snippets.

@proudlygeek
Forked from odino/desc.md
Created March 3, 2014 11:12

Revisions

  1. @odino odino revised this gist Feb 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion desc.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Coding challenge: cartified!

    **Hey JavaScript talents, here at [namshi.com](https://en-ae.namshi.com), we are [looking for you](https://www.angularjobs.com/posts/658-senior-frontend-developer-team-lead-at-namshi-in-dubai-remote-or-on-site)! Submit this coding challenge at [email protected] and we'll get back to you as soon as possible!**
    **Hey JavaScript talents, here at [namshi.com](https://en-ae.namshi.com), we are [looking for you](https://www.angularjobs.com/posts/658-senior-frontend-developer-team-lead-at-namshi-in-dubai-remote-or-on-site)! Submit this coding challenge to [email protected] and we'll get back to you as soon as possible!**

    Your task is to implement a basic shopping cart for a website, following these basic rules:

  2. @odino odino revised this gist Feb 23, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion desc.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Coding challenge: cartified!

    **Hey JavaScript talents, here at [namshi.com](https://en-ae.namshi.com), we are looking for you! Submit this coding challenge at [email protected] and we'll get back to you as soon as possible!**
    **Hey JavaScript talents, here at [namshi.com](https://en-ae.namshi.com), we are [looking for you](https://www.angularjobs.com/posts/658-senior-frontend-developer-team-lead-at-namshi-in-dubai-remote-or-on-site)! Submit this coding challenge at [email protected] and we'll get back to you as soon as possible!**

    Your task is to implement a basic shopping cart for a website, following these basic rules:

  3. @odino odino revised this gist Feb 23, 2014. 1 changed file with 18 additions and 1 deletion.
    19 changes: 18 additions & 1 deletion template.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,20 @@
    angular.module('services.cart', [])
    .service('Cart', ['$rootScope', 'Reviewer', function ($rootScope, Reviewer) {
    var getCart
    var getCart = function(){};

    var addItem = function(){};

    var addItems = function() {};

    var save = function() {};

    var remove = function () {};

    var clear = function() {};

    var persist = function() {};

    var changeQuantity = function (){};

    var refresh = function() {};
    }]);
  4. @odino odino revised this gist Feb 23, 2014. 2 changed files with 4 additions and 19 deletions.
    4 changes: 3 additions & 1 deletion desc.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    # Coding challenge: cartified!

    **Hey JavaScript talents, here at [namshi.com](https://en-ae.namshi.com), we are looking for you! Submit this coding challenge at [email protected] and we'll get back to you as soon as possible!**

    Your task is to implement a basic shopping cart for a website, following these basic rules:

    * the cart needs to be implemented as an AngularJS service
    @@ -48,4 +50,4 @@ You are not allowed to inject any dependency on the Cart service other than the

    Another thing to consider: the cart should be working even when the user has multiple browser tabs open and is adding products from each of them.

    We are **not** going to check the submitted script for syntax errors: concentrate on the design of the `Cart` service, we don't need to check for the small things now :)
    We are **not** going to check the submitted script for syntax errors: concentrate on the design of the `Cart` service, we don't need to check for the small things
    19 changes: 1 addition & 18 deletions template.js
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,3 @@
    angular.module('services.cart', [])
    .service('Cart', ['$rootScope', 'Reviewer', function ($rootScope, Reviewer) {
    var getCart = function(){};

    var addItem = function(){};

    var addItems = function() {};

    var save = function() {};

    var remove = function () {};

    var clear = function() {};

    var persist = function() {};

    var changeQuantity = function (){};

    var refresh = function() {};
    }]);
    var getCart
  5. @odino odino revised this gist Feb 23, 2014. 2 changed files with 2 additions and 4 deletions.
    2 changes: 1 addition & 1 deletion desc.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ For some of the methods mentioned in the empty Cart service, we thought of givin

    ### Save

    Checks if the cart can be persisted: if so, it `persist`s it.
    Checks if the cart can be persisted through the `Reviewer` service: if so, it `persist`s it.

    ### Clear

    4 changes: 1 addition & 3 deletions template.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    angular.module('services.cart', [])
    .service('Cart', ['$rootScope', 'Reviewer', function ($rootScope, Reviewer) {
    var cartService = this;

    .service('Cart', ['$rootScope', 'Reviewer', function ($rootScope, Reviewer) {
    var getCart = function(){};

    var addItem = function(){};
  6. @odino odino revised this gist Feb 23, 2014. 2 changed files with 2 additions and 1 deletion.
    1 change: 1 addition & 0 deletions desc.md
    Original file line number Diff line number Diff line change
    @@ -38,6 +38,7 @@ Notifies the application that the cart has been persisted, so that other parts o
    You are not allowed to inject any dependency on the Cart service other than the ones provided:

    * `$rootScope`: you might want to use it for whatever reason (for example, triggering events)
    * `Reviewer`: it's an angular service that will review the contents of the cart (`Reviewer.review(cart)`, returns a promise)

    ## What are we going to look for?

    2 changes: 1 addition & 1 deletion template.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    angular.module('services.cart', [])
    .service('Cart', ['$rootScope', function ($rootScope) {
    .service('Cart', ['$rootScope', 'Reviewer', function ($rootScope, Reviewer) {
    var cartService = this;

    var getCart = function(){};
  7. @odino odino revised this gist Feb 23, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions desc.md
    Original file line number Diff line number Diff line change
    @@ -45,4 +45,6 @@ You are not allowed to inject any dependency on the Cart service other than the
    * clear, coincise, DRY implementation
    * appropriate naming conventions

    Another thing to consider: the cart should be working even when the user has multiple browser tabs open and is adding products from each of them.

    We are **not** going to check the submitted script for syntax errors: concentrate on the design of the `Cart` service, we don't need to check for the small things now :)
  8. @odino odino created this gist Feb 23, 2014.
    48 changes: 48 additions & 0 deletions desc.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    # Coding challenge: cartified!

    Your task is to implement a basic shopping cart for a website, following these basic rules:

    * the cart needs to be implemented as an AngularJS service
    * the cart should be retrieved from the localStorage, where it's stored under the key `cart`
    * every time an action is performed on the cart, it should be persisted on the localStorage
    * the cart should only know about item IDs and their quantity
    * you will write the cart by implementing the methods of the provided cart service in the `template.js` file contained in this gist: please fork it and submit your implementation
    * it should take you less than 1 hour to come up with an implementation, but we won't put any time limit for this challenge

    ## Methods explanation

    For some of the methods mentioned in the empty Cart service, we thought of giving you some explanation to better understand what they're there for.

    ### Save

    Checks if the cart can be persisted: if so, it `persist`s it.

    ### Clear

    Empties the cart

    ### Persist

    Persist the cart on the localStorage

    ### changeQuantity

    Changes the quantity of one of the items in the cart.

    ### Refresh

    Notifies the application that the cart has been persisted, so that other parts of the app can modify themselves based on the latest cart update.

    ## Dependencies

    You are not allowed to inject any dependency on the Cart service other than the ones provided:

    * `$rootScope`: you might want to use it for whatever reason (for example, triggering events)

    ## What are we going to look for?

    * the fewer lines of code, the better
    * clear, coincise, DRY implementation
    * appropriate naming conventions

    We are **not** going to check the submitted script for syntax errors: concentrate on the design of the `Cart` service, we don't need to check for the small things now :)
    22 changes: 22 additions & 0 deletions template.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    angular.module('services.cart', [])
    .service('Cart', ['$rootScope', function ($rootScope) {
    var cartService = this;

    var getCart = function(){};

    var addItem = function(){};

    var addItems = function() {};

    var save = function() {};

    var remove = function () {};

    var clear = function() {};

    var persist = function() {};

    var changeQuantity = function (){};

    var refresh = function() {};
    }]);