Skip to content

Commit 392c0ab

Browse files
committed
#adding new files
1 parent 9195ba5 commit 392c0ab

File tree

4 files changed

+262
-31
lines changed

4 files changed

+262
-31
lines changed

04_functions.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// 1 Функции
2+
// Function Declaration
3+
// function greet(name) {
4+
// console.log('Привет, ', name)
5+
// }
6+
7+
// Function Expression
8+
// const greet2 = function greet2(name) {
9+
// console.log('Привет 2, ', name)
10+
// }
11+
12+
13+
14+
15+
// greet('Васек')
16+
// greet2('Серега')
17+
// console.log(typeof greet)
18+
// console.dir(greet)
19+
20+
// 2 Анонимные функции
21+
// let counter = 0
22+
// const interval = setInterval(function() {
23+
// if (counter === 5) {
24+
// clearInterval(interval) //clearTimeout
25+
// } else {
26+
// console.log(++counter)
27+
// }
28+
// }, 1000)
29+
30+
// 3 Стрелочные функции
31+
// function greet(nameA) {
32+
// console.log('Привет, ', nameA)
33+
// }
34+
35+
// const arrow = (nameA, age) => {
36+
// console.log('Привет, ', nameA, age)
37+
// }
38+
39+
// const arrow2 = nameA => console.log('Привет, ', nameA)
40+
41+
// // arrow2('Sergey')
42+
43+
// const pow2 = num => {
44+
// return num ** 2
45+
// }
46+
47+
// const pow3 = num => num ** 2
48+
49+
50+
// console.log(pow3(5))
51+
52+
// 4 Параметры по умолчанию
53+
// const sum = (a = 2, b = a * 2) => a + b
54+
// console.log(sum())
55+
56+
// function sumAll(...all) {
57+
// let result = 0
58+
// for (let num of all) {
59+
// result += num
60+
// }
61+
// return result
62+
// }
63+
64+
// const res = sumAll(1, 2, 3, 4, 5)
65+
// console.log(res)
66+
67+
// 5 Замыкания
68+
// function createMember(nameA) {
69+
// return function(lastName) {
70+
// console.log(nameA, lastName)
71+
// }
72+
// }
73+
74+
// const logWithLastName = createMember('Sergey')
75+
// console.log(logWithLastName('Bagdasaryan'))
76+
// console.log(logWithLastName('Terentyev'))
77+
78+

05_arrays.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Массивы
2+
const cars = ['Mazda', 'Ford', 'BMW', 'Mersedes']
3+
// const people = [
4+
// {name: 'Sergey', budget: 3500},
5+
// {name: 'Victoria', budget: 3200},
6+
// {name: 'Elizabeth', budget: 1500},
7+
// ]
8+
const fib = [1, 1, 2, 3, 5, 8, 13, 21]
9+
// console.log(cars)
10+
11+
// Function
12+
// function addItemToEnd() {
13+
14+
// }
15+
16+
// Method
17+
// cars.push('Hyundai')
18+
// console.log(cars)
19+
20+
// cars.unshift('Lada')
21+
// console.log(cars)
22+
23+
// const firstItem = cars.shift()
24+
// const lastItem = cars.pop()
25+
// console.log(firstItem)
26+
// console.log(lastItem)
27+
// console.log(cars)
28+
29+
// console.log(cars.reverse())
30+
31+
// const index = cars.indexOf('BMW')
32+
// cars[index] = 'Audi'
33+
// console.log(cars)
34+
// let foundedPerson
35+
// for (const person of people) {
36+
// if (person.budget === 3500) {
37+
// foundedPerson = person
38+
// }
39+
// }
40+
41+
// console.log(foundedPerson)
42+
43+
// const index = people.findIndex(function(person) {
44+
// return person.budget === 3500
45+
// })
46+
// console.log(people[index])
47+
// const person = people.find(function(person) {
48+
// return person.budget === 35002
49+
// })
50+
// console.log(person)
51+
52+
// const person = people.find(person => person.budget === 3500)
53+
// console.log(person)
54+
55+
// console.log(cars.includes('Mazda'))
56+
57+
// const upperCaseCars = cars.map(car => {
58+
// return car.toUpperCase()
59+
// })
60+
61+
const pow2 = num => num ** 2
62+
// const sqrt = num => Math.sqrt(num)
63+
64+
// const pow2Fib = fib.map(pow2).map(Math.sqrt)
65+
// console.log(pow2Fib)
66+
// const pow2Fib = fib.map(pow2)
67+
// const filteredNumbers = pow2Fib.filter(num => num > 20)
68+
// console.log(pow2Fib)
69+
// console.log(filteredNumbers)
70+
71+
72+
73+
// Задача 1
74+
// const text = 'Я долбаеб и мы учимся в юургу'
75+
// const reverseText = text.split('')
76+
// console.log(reverseText)
77+
// console.log(reverseText.reverse().join(''))
78+
79+
const people = [
80+
{name: 'Sergey', budget: 3500},
81+
{name: 'Victoria', budget: 3200},
82+
{name: 'Elizabeth', budget: 1500},
83+
]
84+
85+
const allBudget = people
86+
.filter(person => person.budget > 2000)
87+
.reduce((acc, person) => {
88+
acc += person.budget
89+
return acc
90+
}, 0)
91+
92+
console.log(allBudget)

06_objects.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// Объекты
2+
const person = {
3+
nameA: 'Sergey',
4+
age: 20,
5+
isProgrammer: true,
6+
languages: ['ru', 'en', 'de'],
7+
// 'complex key': 'Complex value',
8+
// ['key_' + (1 + 3)]: 'Computed key', // key_4
9+
greet() {
10+
console.log('Greetings from Armenia!')
11+
},
12+
info() {
13+
// console.log('this:', this)
14+
console.info('Информация про человека по имени:', this.nameA)
15+
}
16+
}
17+
18+
// console.log(person.nameA)
19+
// const ageKey = 'age'
20+
// console.log(person[ageKey])
21+
// console.log(person['complex key'])
22+
// console.log(person)
23+
// person.greet()
24+
25+
// person.age++
26+
// person.languages.push('am')
27+
// // person['key_4'] = undefined
28+
// delete person['key_4']
29+
30+
// console.log(person)
31+
// console.log(person['key_4'])
32+
33+
// const name = person.nameA
34+
// const age = person.age
35+
// const languages = person.languages
36+
37+
// const {nameA, age: personAge = 10, languages} = person
38+
// console.log(person)
39+
40+
// for (let key in person) {
41+
// if (person.hasOwnProperty(key)) {
42+
// console.log('key:', key)
43+
// console.log('value:', person[key])
44+
// }
45+
// }
46+
47+
48+
// Object.keys(person).forEach((key) => {
49+
// console.log('key:', key)
50+
// console.log('value:', person[key])
51+
// })
52+
53+
54+
// Context
55+
// person.info()
56+
57+
const logger = {
58+
keys() {
59+
console.log('Object Keys: ', Object.keys(this))
60+
},
61+
62+
keysAndValues() {
63+
// Object.keys(this).forEach((key) => {
64+
// console.log(`"${key}": ${this[key]};`)
65+
// })
66+
// const self = this
67+
Object.keys(this).forEach(function(key) {
68+
console.log(`"${key}": ${this[key]};`)
69+
}.bind(this))
70+
},
71+
72+
withParams(top = false, between = false, bottom = false) {
73+
if (top) {
74+
console.log('---- Start ----')
75+
}
76+
Object.keys(this).forEach((key, index, array) => {
77+
console.log(`"${key}": ${this[key]};`)
78+
if (between && index !== array.length - 1) {
79+
console.log('--------------')
80+
}
81+
})
82+
83+
if (bottom) {
84+
console.log('---- End ----')
85+
}
86+
}
87+
}
88+
89+
90+
// logger.keysAndValues.call(person)
91+
logger.withParams.call(person, true, true, true)
92+
logger.withParams.apply(person, [true, true, true])

app.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +0,0 @@
1-
// 1 Функции
2-
// Function Declaration
3-
// function greet(name) {
4-
// console.log('Привет, ', name)
5-
// }
6-
7-
// Function Expression
8-
// const greet2 = function greet2(name) {
9-
// console.log('Привет 2, ', name)
10-
// }
11-
12-
13-
14-
15-
// greet('Васек')
16-
// greet2('Серега')
17-
// console.log(typeof greet)
18-
// console.dir(greet)
19-
20-
// 2 Анонимные функции
21-
// let counter = 0
22-
// const interval = setInterval(function() {
23-
// if (counter === 5) {
24-
// clearInterval(interval) //clearTimeout
25-
// } else {
26-
// console.log(++counter)
27-
// }
28-
// }, 1000)
29-
30-
// 3 Стрелочные функции
31-

0 commit comments

Comments
 (0)