Day 7 — Arrays — basics and iteration
Lesson
Topic 1 Part 1
const f = ['a','b','c'];
console.log(f.at(-1));
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 2 Part 2
const numbers = [1,2,3,4,5];
numbers.forEach(n => console.log(n*2));
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 3 Part 3
const doubled = numbers.map(n => n*2);
console.log(numbers);
console.log(doubled);
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 4 Part 4
const prices = [100,200,300];
const gst = prices.map(n => n*1.18);
console.log(gst)
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 5 Part 5
console.log("-----------------------------------------------------------");
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 6 Part 6
[1,2,3].forEach(n => console.log(n*2));
console.log([1,2,3].map(n => n*2))
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 7 Part 7
console.log("---------------------------------------------------------------------");
const scoring = [89,23,56,47,88,95];
const pass = scoring.filter(n => n>= 50);
console.log(pass);
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 8 Part 8
const fistFail = scoring.find(n => n<30);
console.log(fistFail)
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 9 Part 9
console.log(scoring.some(n => n>90));
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 10 Part 10
console.log(scoring.every(n => n>60));
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 11 Part 11
console.log("------------------------------------------------------------------")
const numbers3 = [4,5,6,7,8];
const max = numbers.reduce((a,n)=> n>a ? n : a, -Infinity);
console.log(max)
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 12 Part 12
const a = [1,2,3,4]
const b = [5,6,7,8]
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 13 Part 13
const acpy = [...a];
console.log(acpy)
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 14 Part 14
const merged = [...a,...b]
console.log(merged)
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 15 Part 15
const newele = [...a,99,...b]
console.log(newele)
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.
Section 16 Part 16
console.log(Math.max(...a))
Code below mirrors ../js/lesson.js. Open DevTools → Console to see output when the script runs.