How to do it...

  1. Open your command-line application, and navigate to your workspace.
  2. Create a new folder named 10-05-reduce-to-transform-data.
  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 with an array of nationality strings:
// main.js 
export function main() { 
  const nationalities = [ 
    'American', 
    'American', 
    'Chinese', 
    'American', 
    'Chinese', 
    'Chinese', 
    'Soviet', 
    'Soviet' 
  ]; 
} 
  1. Use the reduce method to count the different nationalities:
// main.js 
export function main() { 
  //... 
const nationalityCount = nationalities.reduce((acc, nationality) => { 
    acc[nationality] = acc[nationality] || 0; 
    acc[nationality] ++; 
    return acc; 
  }, {}); 
 
  console.log('Nationalities:', nationalityCount); 
} 
  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
3.15.39.190