Skip to content

Instantly share code, notes, and snippets.

View buymed-hoangpham's full-sized avatar
💻
Practice makes Perfect

Hoangthu2 buymed-hoangpham

💻
Practice makes Perfect
View GitHub Profile
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;
const trips = [
{ to: 'Brazil', distance: 1000 },
{ to: 'Chine', distance: 2500 },
{ to: 'India', distance: 3000 },
];
const totalDistanceTraveled = trips.reduce(
(sum, cur) => (sum += cur.distance),
0
);
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);
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);
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;
}, []);
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}$`
@buymed-hoangpham
buymed-hoangpham / index.js
Created September 11, 2022 08:55
pratice
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 },
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');
@buymed-hoangpham
buymed-hoangpham / index.js
Created September 10, 2022 09:59
practice
const peopleNameArray = ['William', 'Collin', 'Stephen'];
const showPeopleName = function (name) {
console.log(`Hello ${name}`);
};
peopleNameArray.forEach(showPeopleName);
peopleNameArray.map(showPeopleName);
// 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) {