Starting Small explainer


#1

The aim of this puzzle: Remove the first 2 elements from the array.

Walkthrough of the solution: The televisions variable is an array of objects. If you wanted to remove one from the array, you could use .pop(), but that would take it from the end of the array. If you want to “pop” off the 1st element, you can use .shift() instead.

The starter code already shifts off the 1st element and prints it out. The original array is now 1 item smaller. To remove and print the new 1st element, you can use televisions.shift() and put that inside of printTV().

Sample code solution:
(Tap below to reveal)

import { televisions } from 'grasshopper.store';

function printTV(tv) {
  console.log(tv.size + ' for $' + tv.price);
}

televisions.forEach(printTV);
console.log('The smallest TV:');
printTV(televisions.shift());
console.log('The next smallest TV:');
printTV(televisions.shift());

JavaScript Concepts: Binary Expression (+ concatenation), console.log(), .forEach(), import, .shift()


#2