-
-
Save QuocCao-dev/386801a9a543389ac3350623694c0b16 to your computer and use it in GitHub Desktop.
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 }, | |
| { jersey: 33, name: "Patrick Ewing", position: "Center", PPG: 20.2 }, | |
| ]; | |
| const loopName = (value) => | |
| console.log( | |
| `${value.jersey} - ${value.name} -- Position: ${ | |
| value.position | |
| } - RPP: ${Math.ceil(value.PPG)}` | |
| ); | |
| players.forEach(loopName); |
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 showProductInfo = (product) => { | |
| console.log(`Name: ${product.name} Price. - Price: ${product.price}$`); | |
| }; | |
| products.forEach(showProductInfo); |
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 conversionCurrencyUnit = (value) => | |
| `${value.name} is ${value.price * 200} rupies`; | |
| const newCars = cars.map(conversionCurrencyUnit); |
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 getPremium = (value) => value.premium; | |
| const newArr = channels.filter(getPremium); | |
| console.log(newArr); |
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
| // cach 1 | |
| let totalDistance = 0; | |
| trips.forEach((trip) => { | |
| totalDistance += trip.distance; | |
| }); | |
| totalDistance | |
| // cach 2 | |
| const totalDistance = trips.reduce((acc, cur) => acc + 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 result = computers.reduce( | |
| (acc, cur) => { | |
| if (cur.os === "Windows") acc.numWins += 1; | |
| if (cur.os === "Mac") acc.numMacs += 1; | |
| return acc; | |
| }, | |
| { | |
| numWins: 0, | |
| numMacs: 0, | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment