Day 9 — ES6+ patterns
Homework
Problem 1 Part 1
const obj = { first: "Priya", last: "Sharma", city: "Jaipur" };
console.log(`${first} ${last} from ${city}`)
Reference solution lives in ../js/homework.js (loaded at the bottom of this page).
Problem 2 Part 2
const arr = [1,2,3,4,5,6]
const [head,...tail] = arr;
console.log(head)
console.log(tail)
Reference solution lives in ../js/homework.js (loaded at the bottom of this page).
Problem 3 Part 3
function multiply(...nums) {
return nums.reduce((a,c) => a*c,1);
}
Reference solution lives in ../js/homework.js (loaded at the bottom of this page).
Problem 4 Part 4
console.log(multiply(2, 3, 4));
console.log(multiply(5));
console.log(multiply());
Reference solution lives in ../js/homework.js (loaded at the bottom of this page).
Problem 5 Part 5
const user = {
name: "Aarav",
age: 21,
city: "Delhi"
};
Reference solution lives in ../js/homework.js (loaded at the bottom of this page).
Problem 6 Part 6
const updatedUser = {...user,age: 22};
console.log(user);
console.log(updatedUser)
Reference solution lives in ../js/homework.js (loaded at the bottom of this page).