This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const computers = [ | |
| { type: 'Laptop', price: 124, os: 'Windows' }, | |
| { type: 'Desk', price: 124, os: 'Mac' }, | |
| { type: 'Desk', price: 124, os: 'Windows' }, | |
| { type: 'Laptop', price: 124, os: 'Mac' }, | |
| { type: 'Laptop', price: 124, os: 'Windows' }, | |
| ]; | |
| let totalTotalMacComputers = 0; | |
| let totalTotalWindowsComputers = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const trips = [ | |
| { to: 'Brazil', distance: 1000 }, | |
| { to: 'Chine', distance: 2500 }, | |
| { to: 'India', distance: 3000 }, | |
| ]; | |
| const totalDistanceTraveled = trips.reduce( | |
| (sum, cur) => (sum += cur.distance), | |
| 0 | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const channels = [ | |
| { name: 'HBO', premium: true }, | |
| { name: 'LIFE', premium: false }, | |
| { name: 'Max', premium: true }, | |
| { name: 'Cooking channel', premium: false }, | |
| { name: 'WOBI', premium: false }, | |
| ]; | |
| const premiumChannels = channels.filter((channel) => channel.premium); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const cars = [ | |
| { name: 'Ford', price: 200 }, | |
| { name: 'Nissan', price: 400 }, | |
| { name: 'Nissan', price: 600 }, | |
| ]; | |
| const showString = (car) => `${car.name} is ${car.price * 200} rupies`; | |
| const messages = cars.map((car) => showString(car)); | |
| console.log('🚀 ~ file: index.js ~ line 11 ~ messages ~ messages', messages); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const paintings = [ | |
| { name: 'Mona lisa', width: 200, height: 200 }, | |
| { name: 'The scream', width: 400, height: 600 }, | |
| { name: 'The last supper', width: 600, height: 700 }, | |
| ]; | |
| const messages = paintings.reduce((acc, cur) => { | |
| acc.push(`The ${cur.name} is ${cur.width} x ${cur.height}`); | |
| return acc; | |
| }, []); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const products = [ | |
| { name: 'Iphone', price: 200 }, | |
| { name: 'Motorola', price: 70 }, | |
| { name: 'Samsung', price: 150 }, | |
| { name: 'Sony', price: 98 }, | |
| { name: 'Windows pone', price: 10 }, | |
| ]; | |
| const result = products.map( | |
| (product) => `Name: ${product.name} Price. - Price: ${product.price}$` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const players = [ | |
| { jersey: 56, name: 'Djounte Murray', position: 'Point guard', PPG: 2.6 }, | |
| { jersey: 98, name: 'Dennis Rodman', position: 'Small Forward', PPG: 10.8 }, | |
| { | |
| jersey: 1, | |
| name: 'Michael Jordan', | |
| position: 'Small Forward', | |
| PPG: 345.6, | |
| }, | |
| { jersey: 2, name: 'Lebron James', position: 'Shooting Guard', PPG: 26.7 }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const showProfile = (name, lastname, age, profession, salary) => { | |
| console.log( | |
| `My name is ${name} ${lastname}, i'm ${age} years old. I work as ${profession} and make $${salary}.` | |
| ); | |
| }; | |
| showProfile('Hoang', 'Pham Minh', '18', 'Front-end Developer', '10'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const peopleNameArray = ['William', 'Collin', 'Stephen']; | |
| const showPeopleName = function (name) { | |
| console.log(`Hello ${name}`); | |
| }; | |
| peopleNameArray.forEach(showPeopleName); | |
| peopleNameArray.map(showPeopleName); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 412. Fizz Buzz | |
| /** | |
| * @param {number} n | |
| * @return {string[]} | |
| */ | |
| var fizzBuzz = function(n) { | |
| let arr = []; | |
| for (let i = 1; i <= n; i++) { | |
| if (i % 3 === 0 && i % 5 === 0) { |