raineroviir / codechallenge

My node server and library model
0 stars 0 forks source link

Add and remove book methods should be attached to an object #1

Open brookr opened 9 years ago

brookr commented 9 years ago

Rather than free-floating methods, the methods to add/remove a book should be behaviors of the Shelf object.

raineroviir commented 9 years ago

Array.prototype.addBookToShelfTwo = function(Book) { this.push(Book); return this; }

Array.prototype.removeBookFromShelf = function(title) { var index = this.indexOf(title); this.splice(index, 1); return this; }

My shelf objects are new Array Objects so i added the methods to the Array prototype

brookr commented 9 years ago

Improvements here look nice.

How about making actual Book objects, rather than just adding them by name/author?

brookr commented 9 years ago

Also, it's best for Library and Shelf methods to be attached to their respective prototypes.

Otherwise, very close to the solution we are looking for!

raineroviir commented 9 years ago

Good suggestions, I made the changes

Mohammed-kj commented 7 months ago

Interesting