-
Notifications
You must be signed in to change notification settings - Fork 0
homework-4 #5
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
Merged
Merged
homework-4 #5
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="ru"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <title>test page</title> | ||
| </head> | ||
| <body> | ||
| <script src="src/main.js"></script> | ||
| </body> | ||
| </html> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /* | ||
| * Напишите функцию которая будет принимать 1 аргумент и в зависимости от типа аргумента | ||
| * | ||
| * Если тип аргумента число или объект -> возвращать true | ||
| * Если тип аргумента функция -> возвращать false | ||
| * Если тип аргумента Строка и длина этой строки не равна 10 -> возвращать "длина вашей строки: <длина строки> | ||
| * Если длина 10 -> 'you win' | ||
| * */ | ||
| function returnType(arg){ | ||
| if(typeof arg == 'number' || typeof arg == 'object' ){ | ||
| return true | ||
| } else if (typeof arg == 'function'){ | ||
| return false | ||
| } else if(typeof arg == 'string'){ | ||
| if(arg.length == 10){ | ||
| return 'you win' | ||
| } | ||
| return `Длинна вашей строки: ${arg.length}` | ||
| } | ||
| } | ||
| console.log(returnType(3)); | ||
| console.log(returnType({})); | ||
| console.log(returnType(function(){})); | ||
| console.log(returnType('helloworld')); | ||
| console.log(returnType('hello world')); | ||
| // Задача в классе | ||
| let webStore = { | ||
| category: { | ||
| notebook: ['Lenova', 'Asus', 'Xiaomi'], | ||
| mobile:['Nokia', 'Sony', 'Apple'] | ||
| } | ||
| }; | ||
| let category = webStore.category; | ||
| for(let key in category){ | ||
| let someValue = category[key]; | ||
| console.log('Категория:', key); | ||
| for(let i = 0; i < someValue.length; i++){ | ||
| console.log(someValue[i]); | ||
| } | ||
| } | ||
| /* | ||
| 1. Напишите функцию которая принимает 2 числа | ||
| и возвращает массив содержащий числа между первым числом и вторым числом; | ||
| */ | ||
|
|
||
| function numbersBetween(a, b) { | ||
| let newArr = []; | ||
| for(let i = a; i <= b; i++){ | ||
| newArr.push(i); | ||
| } | ||
| return newArr | ||
| } | ||
|
|
||
| console.log(numbersBetween(3, 5)); | ||
| // 3, 4, 5 | ||
|
|
||
| console.log(numbersBetween(10, 12)); | ||
| // 10, 11, 12 | ||
|
|
||
|
|
||
| /* | ||
| 2. Перепишите задачу FizzBuzz, но с использованием цикла. | ||
| Расчет чисел должен идти до 100 | ||
| */ | ||
|
|
||
| // 1. FizzBuzz 3, 5, 3 && % 5 | ||
|
|
||
| function fizzBuzz(num) { | ||
| let someRes = (num % 15 == 0) ? 'FizzBuzz' : | ||
| (num % 3 == 0) ? 'Fizz' : | ||
| (num % 5 == 0) ? 'Buzz' : num ; | ||
| return someRes | ||
| } | ||
| function fizzBuzz100() { | ||
| for(let i = 1; i <= 100; i++) { | ||
| console.log(fizzBuzz(i)); | ||
| } | ||
| } | ||
| fizzBuzz100(); | ||
|
|
||
| /* | ||
| 3. Напишите функцию которая принимает 1 аргумент - массив | ||
| И возвращает новый массив содержащий типы значений переменных | ||
| */ | ||
|
|
||
| let arr = [1, null, undefined, 'str', {}, [], function() {}]; | ||
|
|
||
| function newArr(arr){ | ||
| let newArray = []; | ||
| for(let i = 0; i < arr.length; i++){ | ||
| let someValue = arr[i]; | ||
| newArray.push( typeof someValue); | ||
| } | ||
| return newArray | ||
| } | ||
| console.log(newArr(arr)); | ||
| /* | ||
| 1. @@SUPER@@. Вам дан массив array, содержащий внутри объекты. | ||
| Напишите функцию которая внутри цикла проходится по каждому элементу массива | ||
| И проверяет какой тип данных содержит свойство age, если тип данных NaN, | ||
| тогда добавляет данному объекту свойство unknownAge: true | ||
| 2. На основании нового массива, создайте новую функцию, которая вернет новый массив | ||
| содержащий все объекты содержащие свойство unknownAge: true | ||
| */ | ||
| let array = Array.from({ length: 35 }, | ||
| (value, index) => (index % 2 ? { age: index + 2 } : { age: NaN }), | ||
| ); | ||
| function solution(arr) { | ||
| for (let i= 0; i < arr.length; i++) { | ||
| let simpleElement = arr[i]; | ||
| if (isNaN(simpleElement.age)) { | ||
| simpleElement.unknownAge = 'true'; | ||
| } | ||
| } | ||
| return unknownAge(arr); | ||
| } | ||
| function unknownAge(arr) { | ||
| let newArr = []; | ||
| for (let i = 0; i < arr.length; i++) { | ||
| let simpleElement = arr[i]; | ||
| if (simpleElement.unknownAge) { | ||
| newArr.push(simpleElement); | ||
| } | ||
| } | ||
| return newArr; | ||
| } | ||
| console.log(solution(array)); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
please remove blank lines