0
How programming concepts like functions, arrays, objects can be applied ?
Hey guys , lets discuss about how programming concepts like functions, arrays , objects can be applied in real life ... Leave your opinion about that and your advice!
1 Respuesta
+ 2
Functions are pieces of reusable code. The beauty of functions is you only have to define the function once but you can use it as many times as you want, and you can pass different arguments.
Arrays are good for holding collections of items.
Objects are good for holding several values paired up with a key.
Example - shop:
* Objects can be used for the items the shop sells. Each item object could have key-value pairs like
name: "orange",
price: 1.00
* Arrays can be used for the collections such as stock = [] which would hold the item objects which are for sale. Other examples of array usage are lists of items in a customer's cart & historical sold items.
* Functions can be used to make a sale. This function could look something like:
const sell = (items) => {
// go through the array of items to:
// calculate the total price
// Request amount from customer
// update the account of the shop
// update the shop's stock & sold items
}