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 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 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 trips = [
{ to: 'Brazil', distance: 1000 },
{ to: 'Chine', distance: 2500 },
{ to: 'India', distance: 3000 },
];
const totalDistanceTraveled = trips.reduce(
(sum, cur) => (sum += cur.distance),
0
);
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;
@buymed-hoangpham
buymed-hoangpham / index.js
Created September 13, 2022 09:11
exercise
// 9.
const removeEven = (arr) => {
return arr.filter((el) => el % 2 !== 0);
};
console.log(removeEven([1, 2, 4, 5, 10, 6, 3]));
// 10.
const capitalize = (words) => {
return words.map((el) => el.charAt(0).toUpperCase() + el.slice(1));
@buymed-hoangpham
buymed-hoangpham / index.js
Created September 23, 2022 10:51
Homework
//1.
const subLength = (str, char) => {
let charInStr = [],
lowerStr = str.toLowerCase().split(''),
length = 0;
lowerStr.forEach((val, index) => {
if (val === char) {
charInStr.push(index);
}
const name = "Francis", lastname = "Jones", age = 23;
let obj;
function createObject(name,lastname,age){
return obj = {
name,
lastname,
age,
}
}
// 5
const getLocation = (city, country = 'Italy', continent = 'Europe') =>
console.log(continent, country, city);
getLocation('Milan');
// Europe Italy Milan
getLocation('Paris', 'France');
// Europe France Paris
const countCharacters = (str) => {
const result = {};
const arr = str.split('');
for (word of arr) {
if (result[word]) {
result[word]++;
} else {
result[word] = 1;
function twoFer(name: string = "you"): string {
return `One for ${name}, one for me`
}
console.log(twoFer())
console.log(twoFer("Elton"))
function isLeapYear(year: number): boolean {
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)
}