-
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
домашнее задание номер 9 #6
Open
maxeasy18
wants to merge
2
commits into
master
Choose a base branch
from
homework_9
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 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 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,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Home work 9</title> | ||
</head> | ||
<body> | ||
|
||
<script src="src/main.js"></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
|
||
// Отобразите достаточно ли у developers навыков ? | ||
// Отобразите всех разработчиков и вызовете у каждого | ||
// разработчика метод goodDev -- | ||
/* | ||
* Количество требований к разработчику совпадает с его навыками. | ||
* Используйте в задаче this | ||
* */ | ||
let developer1 = { | ||
skills: ['JavaScript', 'linux', 'html', 'OOP', 'Node.js'], | ||
requirements: ['Node.js', 'JavaScript', 'OOP'], | ||
goodDev: goodDev | ||
}; | ||
let developer2 = { | ||
experience: [ | ||
{ technology: 'java' }, | ||
{ technology: 'c++' }, | ||
{ technology: 'aws' }, | ||
{ technology: 'docker' } | ||
], | ||
requirements: ['java', 'json', 'c++', 'JavaScript'], | ||
goodDev: goodDev | ||
}; | ||
function goodDev() { | ||
let calcObj = (val,obj) => { | ||
return (obj.skills || obj.experience).some(function(arrVal){ | ||
if(typeof arrVal=== 'string'){ | ||
return arrVal === val; | ||
}else{ | ||
return arrVal.technology === val; | ||
} | ||
}); | ||
|
||
} | ||
this.requirements.forEach( val => { | ||
console.log( | ||
`required: ${val} ... ` + | ||
(calcObj(val,this) ? 'success' : 'fail') | ||
); | ||
},this); | ||
} | ||
console.log('\ndeveloper1'); | ||
developer1.goodDev(); | ||
console.log('\ndeveloper2'); | ||
developer2.goodDev(); | ||
// developer 1 | ||
// required: Node.js ... success | ||
// required: JavaScript ... success | ||
// required: OOP ... success | ||
// --- | ||
// developer 2 | ||
// required: json ... fail | ||
// required: JavaScript ... success | ||
// required: Java ... success | ||
// required: OOP ... success | ||
|
||
|
||
|
||
|
||
/* | ||
* | ||
* TASK 2 | ||
* | ||
* | ||
* Напишите функцию принимает 1 аргумент сортирует объект по | ||
* переданному значению (например age или name) | ||
* | ||
* При вызове функции используйте this | ||
* | ||
* */ | ||
let myObject = { | ||
database: [ | ||
{ age: 100, name: 'b' }, | ||
{ age: 15, name: 'c' }, | ||
{ age: 25, name: 'a' } | ||
] | ||
}; | ||
|
||
|
||
myObject.myFilter = function(field) { | ||
return this.database.sort((prev,next) => { | ||
|
||
if(parseInt(prev[field])){ | ||
// console.log(parseInt(prev[field]) > parseInt(next[field]) ? 1 : -1 ); | ||
return parseInt(prev[field]) > parseInt(next[field]) ? 1 : -1 ; | ||
}else{ | ||
return prev[field] > next[field] ? 1 : -1; | ||
} | ||
}); | ||
}; | ||
// {age:15, name:'c'}, {age:25, name:'a'} {age:100, name:'b'} | ||
|
||
// создаю копии массивов, потому что в консоли отображаются потом по последней сортировке, неудобно | ||
console.log(myObject.myFilter('age').slice()); | ||
// {age:25, name:a}, {age:100, name: b} ... | ||
console.log(myObject.myFilter('name').slice()); | ||
|
||
|
||
/* | ||
* TASK 3 | ||
* | ||
* Перепишите homework 5 с использованием методов массивов и | ||
* => arrow functions | ||
* | ||
*/ | ||
////// @ TODO -- LVL Strong Junior | ||
/* | ||
* | ||
* TASK 1 | ||
* Напишите функцию которая принимает 3 аргумента:* | ||
* | ||
* - объект к которому привязывается метод | ||
* - Имя свойства с которым связывается метод | ||
* - Объявление привязываемого метода( функция ) | ||
* | ||
* Если количество аргументов у функции fn совпадает с переданными | ||
* параметрами тогда сохраняет метод в замыкании | ||
* и привязывает функцию к методу объекта | ||
* | ||
* при вызове одного и того же метода с разным количеством аргументов, | ||
* должно давать различный результат | ||
* | ||
* */ | ||
let junior = {}; | ||
// fn.length == arguments.length | ||
|
||
/* | ||
Вариант с замыканием. Минус - замыкание на глобальный скоуп. | ||
*/ | ||
|
||
let arr = []; | ||
function addMethod(object, name, fn) { | ||
arr[fn.length] = fn; | ||
object[name] = function(){ | ||
arr[arguments.length](); | ||
}; | ||
} | ||
|
||
|
||
/* | ||
Вариант с сохранением в свойства самого объекта. | ||
*/ | ||
// function addMethod(object, name, fn) { | ||
// if(!object.vars){ | ||
// object.vars = []; | ||
// } | ||
// object.vars[fn.length] = fn; | ||
// object[name] = function(){ | ||
// this.vars[arguments.length](); | ||
// }; | ||
// } | ||
|
||
|
||
|
||
|
||
addMethod(junior, 'ok', function() { | ||
console.log('zero arguments'); | ||
}); | ||
addMethod(junior, 'ok', function(one) { | ||
console.log('one arguments'); | ||
}); | ||
addMethod(junior, 'ok', function(one, two) { | ||
console.log('two arguments'); | ||
}); | ||
addMethod(junior, 'ok', function(one, two, three) { | ||
console.log('three arguments'); | ||
}); | ||
junior.ok(1, 2, 3); // 'three arguments' | ||
junior.ok(1, 2); // 'two arguments' | ||
junior.ok(1); //'one arguments' | ||
junior.ok(); //'zero arguments' | ||
junior.ok(1, 2, 3); // 'three arguments' | ||
|
||
|
||
console.log(`В коде есть еще вариант, но он не использует замыкания. | ||
Текущий вариант тоже не самый лучший, потому что придумал замкнуть только на глобальный скоуп.`) |
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.
you don't need else-statement there, just return is enough