How programming concepts like functions, arrays, objects can be applied ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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!

2nd Apr 2021, 10:59 PM
Kevin Brian
Kevin Brian - avatar
1 Answer
+ 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 }
2nd Apr 2021, 11:44 PM
CamelBeatsSnake
CamelBeatsSnake - avatar