-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hw 3 #3
base: main
Are you sure you want to change the base?
Hw 3 #3
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>task3</title> | ||
</head> | ||
<body> | ||
<header></header> | ||
<main></main> | ||
<footer></footer> | ||
<script src="js/main.js" defer></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"use strict" | ||
// Получить от юзера число. | ||
// Получить сумму квадаров всех чисел от 1 до числа, которое ввел юзер. Пример: | ||
// Юзер ввел 4 | ||
// (1 * 1) + (2 * 2) + (3 * 3) + (4 * 4) = 30 | ||
// Вывести в консоль результат | ||
// Привести во вторую степерь можно через оператор **. 3 ** 2 = 9 | ||
const num = Number(prompt('Enter your number')); | ||
alert (num); | ||
|
||
const sumSquare = (num) => { | ||
let sum = 0; | ||
for(let i = 1; i <= num; i++){ | ||
sum += i**2; | ||
} | ||
console.log(`The sum is ${sum}`); | ||
} | ||
|
||
sumSquare(num); | ||
|
||
// Есть массив [3, 5, 12, 9, 23, 93, 17] | ||
// Отфильтровать его так, чтобы остались только те числа, которые больше 2 и меньше 20. И потом получить их сумму. | ||
const arr = [3, 5, 12, 9, 23, 93, 17]; | ||
|
||
const arrFilter = arr => { | ||
const filterArr = arr.filter(el => el > 2 && el < 20); | ||
const sum = filterArr.reduce((acc,item) => acc + item); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const sum = filterArr.reduce((acc,item) => acc + item); |
||
|
||
return Array.isArray(arr) ? sum : 'Error is not an array'; | ||
} | ||
|
||
console.log(arrFilter(arr)); | ||
|
||
// Дан массив [[1, 6, 3, '6'], [10, 15, 13, '10']]. Найти сумму элементов, которые являются числами и которые кратны двум | ||
const list = [[1, 6, 3, '6'], [10, 15, 13, '10']]; | ||
const arrTransform = arr => { | ||
|
||
const flatArr = arr.flat(); | ||
const filteredData = flatArr.filter(el => typeof el === 'number' && el % 2 === 0); | ||
const totalSum = filteredData.reduce((acc, item) => acc + item); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const totalSum = filteredData.reduce((acc, item) => acc + item); |
||
|
||
return Array.isArray(arr) ? totalSum : 'Error is not an array'; | ||
} | ||
|
||
console.log(arrTransform(list)); | ||
|
||
// Написать функцию, которая устанавливает новые свойства в объект. | ||
|
||
const keys = prompt('Enter your key'); | ||
const value = prompt('Enter your value'); | ||
|
||
const addPropeties = (key,value,object) => typeof object === 'object' && !object.hasOwnProperty(key) | ||
? { ...object , [key]:value} : 'Уже есть'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. что с форматированием? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prettier решил попробывать , потом понял что не очень идея и отключил, сейчас исправлю оформление! |
||
|
||
const person = {name:'Vlad'}; | ||
const obj = addPropeties(keys,value,person); | ||
console.log(obj); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alert(num);