How to do it...

  1. Open your command-line application, and navigate to your workspace.
  2. Create a new folder named 10-02-using-slice-to-get-subset.
  3. Create a main.js file that defines a new class named Rocket that takes a constructor argument name and assigns it to an instance property:
// main.js 
class Rocket { 
  constructor(name) { 
    this.name = name; 
  } 
   } 
  1. Create a main function that creates several Rocket instances and places them into an array:
// main.js 
export function main() { 
  const saturnV = new Rocket('US: Saturn V'); 
  const falconHeavy = new Rocket('US: Falcon Heavy'); 
  const soyuz = new Rocket('USSR: Soyuz'); 
  const dongFeng = new Rocket('CN: Dong Feng'); 
  const longMarch = new Rocket('CN: Long March'); 
  const rockets = [saturnV, falconHeavy, soyuz, dongFeng, 
longMarch]; }
  1. Divide the Rockets array into three subsets based on the country:
// main.js 
export function main() { 
//.... const americanRockets = rockets.slice(0, 2); const sovietRockets = rockets.slice(2, 3); const chineseRockets = rockets.slice(3, 5); console.log('American Rockets: ', americanRockets); console.log('Soviet Rockets: ', sovietRockets); console.log('Chinese Rockets: ', chineseRockets); }
  1. Start your Python web server and open the following link in your browser:
    http://localhost:8000/.
  2. You should see the following output:

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.151.90