xxxxxxxxxx
76
// other way to declare function
// let setup = function() {
// }
function setup() {
let arr = [1, 3, 4, 6];
// console.log(arr);
// coding intensive way to double all items in an array
// for (let i = 0; i < arr.length; i++) {
// arr[i] *= 2;
// }
// using higher order JS array function "map"
// expects a function to be passed in as argument
// arr = arr.map(doubleIt);
// x becomes every element of an array:
// function doubleIt(x){
// return x*2;
// }
// same as above, but with anonymous function
// arr = arr.map(function(x){
// return x*2;
// });
// same as above, but with anonymous ARROW function
// arr = arr.map((x) => {
// return x*2;
// });
// same as above, but with anonymous ARROW stripped down
// 'lambda function'
// arr = arr.map(x => x*2);
// console.log(arr);
// demonstration of 'higher order' functions...
// this function returns a function as a result
// function multiplier(factor) {
// return function(x) {
// return x * factor;
// }
// }
// let doubler = multiplier(2);
// let tripler = multiplier(3);
// console.log(doubler(2));
// console.log(tripler(2));
let cat = {
name: "jojo",
age: 9,
type: "calico"
};
let catArr = [];
for (let i = 0; i<10; i++){
let c = Object.assign({}, cat);
catArr.push(c);
}
console.log(catArr);
for (let kitty of catArr){
for (let prop in kitty){
console.log(kitty[prop]);
}
}
}