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 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 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 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
| // 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)); |
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
| //1. | |
| const subLength = (str, char) => { | |
| let charInStr = [], | |
| lowerStr = str.toLowerCase().split(''), | |
| length = 0; | |
| lowerStr.forEach((val, index) => { | |
| if (val === char) { | |
| charInStr.push(index); | |
| } |
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 name = "Francis", lastname = "Jones", age = 23; | |
| let obj; | |
| function createObject(name,lastname,age){ | |
| return obj = { | |
| name, | |
| lastname, | |
| age, | |
| } | |
| } |
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
| // 5 | |
| const getLocation = (city, country = 'Italy', continent = 'Europe') => | |
| console.log(continent, country, city); | |
| getLocation('Milan'); | |
| // Europe Italy Milan | |
| getLocation('Paris', 'France'); | |
| // Europe France Paris |
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 countCharacters = (str) => { | |
| const result = {}; | |
| const arr = str.split(''); | |
| for (word of arr) { | |
| if (result[word]) { | |
| result[word]++; | |
| } else { | |
| result[word] = 1; |
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
| 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) | |
| } |