Skip to content

Instantly share code, notes, and snippets.

@rogerprz
Created May 28, 2018 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerprz/89ef7e26193c77f313cc48c85aac8a6b to your computer and use it in GitHub Desktop.
Save rogerprz/89ef7e26193c77f313cc48c85aac8a6b to your computer and use it in GitHub Desktop.
// OOP
class GroceryList{
constructor(items){
this.items = items }
addItem(item) {
this.items.push(item)
}
}
class GroceryItem{
constructor(items){
this.items = items }
addItem(item) {
this.items.push(item)
}
}
// Functional Programming:
function addItem(list, item){
return list.concat(item)
}
// Creating Data:
// OOP
var myGroceryList = new GroceryList([
new GroceryItem("banana", 2.99),
new GroceryItem("beer",12.99 ),
new GroceryItem("apples", 0.98 )
])
// FP
const myGroceyList = [
{name: "banana",price: 2.99},
{name: "Beer",price: .99},
{name: "Apples",price: .99}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment