-
Notifications
You must be signed in to change notification settings - Fork 83
/
05_array.js
85 lines (71 loc) · 2 KB
/
05_array.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const cars = ['Мазда', 'Форд', 'БМВ', 'Мерседс']
// const people = [
// {name: 'Vladilen', budget: 4200},
// {name: 'Elena', budget: 3500},
// {name: 'Victoria', budget: 1700}
// ]
const fib = [1, 1, 2, 3, 5, 8, 13]
// Function
function addItemToEnd() {
}
// Method
// cars.push('Рено')
// cars.unshift('Волга')
//
// const firstCar = cars.shift()
// const lastCar = cars.pop()
// console.log(firstCar)
// console.log(lastCar)
// console.log(cars)
// console.log(cars.reverse())
// console.log(cars)
// const index = cars.indexOf('БМВ')
// cars[index] = 'Porsche'
// console.log(cars)
// let findedPerson
// for (const person of people) {
// if (person.budget === 3500) {
// findedPerson = person
// }
// }
// console.log(findedPerson)
// const index = people.findIndex(function(person) {
// return person.budget === 3500
// })
// const person = people.find(function(person) {
// return person.budget === 3500
// })
// console.log(person)
// const person = people.find(person => person.budget === 3500)
// console.log(person)
// console.log(cars.includes('Мазда!'))
// const upperCaseCars = cars.map(car => {
// return car.toUpperCase()
// })
//
const pow2 = num => num ** 2
// const sqrt = num => Math.sqrt(num)
//
// const pow2Fib = fib.map(pow2).map(Math.sqrt)
// console.log(pow2Fib)
// const pow2Fib = fib.map(pow2)
// const filteredNumbers = pow2Fib.filter(num => num > 20)
// console.log(pow2Fib)
// console.log(filteredNumbers)
// Задача 1
// const text = 'Привет, мы изучаем JavaScript'
// const reverseText = text.split('').reverse().join('')
// console.log(reverseText)
const people = [
{name: 'Vladilen', budget: 4200},
{name: 'Elena', budget: 3500},
{name: 'Victoria', budget: 1700}
]
const allBudget = people
.filter(person => person.budget > 2000)
.reduce((acc, person) => {
acc += person.budget
return acc
}, 0)
console.log(allBudget)
// const displayItems = allItems.filter(item => item.name.indexOf('phone') !== -1)