Created
February 21, 2020 08:53
-
-
Save vladilenm/86df51a1909e1233e8ba9b01e5bf9cd2 to your computer and use it in GitHub Desktop.
This file contains 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 citiesRussia = ['Москва', 'Санкт-Петербург', 'Казань', 'Новосибирск'] | |
const citiesEurope = ['Берлин', 'Прага', 'Париж'] | |
const citiesRussiaWithPopulation = { | |
Moscow: 20, | |
SaintPetersburg: 8, | |
Kazan: 5, | |
Novosibirsk: 3 | |
} | |
const citiesEuropeWithPopulation = { | |
Moscow: 26, | |
Berlin: 10, | |
Praha: 3, | |
Paris: 2 | |
} | |
// Spread | |
console.log(...citiesRussia) | |
console.log(...citiesEurope) | |
const allCities = [...citiesEurope, ...citiesRussia] | |
// const allCities = citiesEurope.concat(citiesRussia) | |
console.log(allCities) | |
console.log({...citiesRussiaWithPopulation}) | |
console.log({...citiesRussiaWithPopulation, ...citiesEuropeWithPopulation}) | |
console.log({...citiesEuropeWithPopulation, ...citiesRussiaWithPopulation}) | |
/// Practice | |
const numbers = [5, 37, 42, 17] | |
console.log(Math.max(5, 37, 42, 17)) | |
console.log(Math.max(...numbers)) | |
console.log(Math.max.apply(null, numbers)) | |
const divs = document.querySelectorAll('div') | |
const nodes = [...divs] | |
console.log(divs, Array.isArray(divs)) | |
console.log(nodes, Array.isArray(nodes)) | |
/// Rest | |
function sum(a, b, ...rest) { | |
return a + b + rest.reduce((a, i) => a + i, 0) | |
} | |
const nums = [1, 2, 3, 4, 5, 6, 7, 8] | |
console.log(sum(...nums)) | |
// const a = nums[0] | |
// const b = nums[1] | |
const [a, b, ...other] = nums | |
console.log(a, b, other) | |
const person = { | |
name: 'Max', | |
age: 20, | |
city: 'Moscow', | |
country: 'Russia' | |
} | |
const {name, age, ...address} = person | |
console.log(name, age, address) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment