diff --git a/.eslintrc.js b/.eslintrc.js index 9db082a8c7..97337109ce 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,84 +1,86 @@ -module.exports = { - extends: ['eslint:recommended', 'airbnb-base'], - env: { - browser: true, - node: true, - jest: true, - es6: true, - }, - parser: 'babel-eslint', - parserOptions: { - sourceType: 'module', - }, - rules: { - 'import/prefer-default-export': 0, - 'import/extensions': 0, - 'max-classes-per-file': 0, - complexity: [0, 11], - 'no-prototype-builtins': 0, - 'prefer-destructuring': 0, - 'no-restricted-globals': 0, - 'consistent-return': 2, - curly: [2, 'multi-line'], - 'default-case': 2, - 'dot-location': 0, - 'dot-notation': [2, { allowKeywords: true }], - eqeqeq: 1, - 'guard-for-in': 1, - 'no-alert': 1, - 'no-caller': 1, - 'no-case-declarations': 2, - 'no-div-regex': 0, - 'no-else-return': 2, - 'no-empty-pattern': 0, - 'no-eq-null': 0, - 'no-eval': 2, - 'no-extend-native': 2, - 'no-extra-bind': 1, - 'no-fallthrough': 2, - 'no-floating-decimal': 2, - 'no-implicit-coercion': 0, - 'no-implied-eval': 2, - 'no-invalid-this': 0, - 'no-iterator': 2, - 'no-labels': [2, { allowLoop: true, allowSwitch: true }], - 'no-lone-blocks': 2, - 'no-loop-func': 1, - 'no-magic-numbers': 0, - 'no-multi-spaces': 2, - 'no-multi-str': 2, - 'no-native-reassign': 2, - 'no-new-func': 2, - 'no-new-wrappers': 2, - 'no-new': 0, - 'no-octal-escape': 2, - 'no-octal': 2, - 'no-console': 0, - 'no-param-reassign': [2, { props: true }], - 'no-process-env': 0, - 'no-proto': 0, - 'no-redeclare': 2, - 'no-return-assign': 2, - 'no-script-url': 2, - 'no-self-compare': 2, - 'no-sequences': 2, - 'no-throw-literal': 2, - 'no-unused-expressions': 2, - 'no-useless-call': 0, - 'no-useless-concat': 0, - 'no-void': 0, - 'no-warning-comments': [0, { terms: ['todo', 'fixme', 'xxx'], location: 'start' }], - 'no-with': 2, - radix: 2, - 'vars-on-top': 0, - 'wrap-iife': [2, 'outside'], - yoda: 2, - }, - settings: { - 'import/resolver': { - node: { - paths: ['./'], - }, - }, - }, -}; +module.exports = { + extends: ['eslint:recommended', 'airbnb-base'], + env: { + browser: true, + node: true, + jest: true, + es6: true, + }, + parser: 'babel-eslint', + parserOptions: { + sourceType: 'module', + }, + rules: { + 'import/prefer-default-export': 0, + 'import/extensions': 0, + 'max-classes-per-file': 0, + complexity: [0, 11], + 'no-prototype-builtins': 0, + 'prefer-destructuring': 0, + 'no-restricted-globals': 0, + 'consistent-return': 2, + curly: [2, 'multi-line'], + 'default-case': 2, + 'dot-location': 0, + 'dot-notation': [2, { allowKeywords: true }], + eqeqeq: 1, + 'guard-for-in': 1, + 'no-alert': 1, + 'no-caller': 1, + 'no-case-declarations': 2, + 'no-div-regex': 0, + 'no-else-return': 2, + 'no-empty-pattern': 0, + 'no-eq-null': 0, + 'no-eval': 2, + 'no-extend-native': 2, + 'no-extra-bind': 1, + 'no-fallthrough': 2, + 'no-floating-decimal': 2, + 'no-implicit-coercion': 0, + 'no-implied-eval': 2, + 'no-invalid-this': 0, + 'no-iterator': 2, + 'no-labels': [2, { allowLoop: true, allowSwitch: true }], + 'no-lone-blocks': 2, + 'no-loop-func': 1, + 'no-magic-numbers': 0, + 'no-multi-spaces': 2, + 'no-multi-str': 2, + 'no-native-reassign': 2, + 'no-new-func': 2, + 'no-new-wrappers': 2, + 'no-new': 0, + 'no-octal-escape': 2, + 'no-octal': 2, + 'no-console': 0, + 'no-param-reassign': [2, { props: true }], + 'no-process-env': 0, + 'no-proto': 0, + 'no-redeclare': 2, + 'no-return-assign': 2, + 'no-script-url': 2, + 'no-self-compare': 2, + 'no-sequences': 2, + 'no-throw-literal': 2, + 'no-unused-expressions': 2, + 'no-useless-call': 0, + 'no-useless-concat': 0, + 'no-void': 0, + 'no-warning-comments': [0, { terms: ['todo', 'fixme', 'xxx'], location: 'start' }], + 'no-with': 2, + 'no-plusplus' : 0, + 'no-bitwise' : 0, + radix: 2, + 'vars-on-top': 0, + 'wrap-iife': [2, 'outside'], + yoda: 2, + }, + settings: { + 'import/resolver': { + node: { + paths: ['./'], + }, + }, + }, +}; diff --git a/src/ex3_js-objects-part1/task-01.js b/src/ex3_js-objects-part1/task-01.js new file mode 100644 index 0000000000..921636f10b --- /dev/null +++ b/src/ex3_js-objects-part1/task-01.js @@ -0,0 +1,11 @@ +const person = { + name: 'Den', + surname: 'Steshin', + age: 26, + birthdate: '26.11.1995', + student: true, + skills: { html: 'expert', css: 'expert', javascript: 'expert' }, + resident: ['Russian Federation', 'Ryazan'], +}; + +delete person.age; diff --git a/src/ex3_js-objects-part1/task-02.js b/src/ex3_js-objects-part1/task-02.js new file mode 100644 index 0000000000..83862b96c2 --- /dev/null +++ b/src/ex3_js-objects-part1/task-02.js @@ -0,0 +1,7 @@ +function showValues(object) { + for (const key in object) { + console.log(key, object[key]); + } +} + +module.exports = showValues(); diff --git a/src/ex3_js-objects-part1/task-03.js b/src/ex3_js-objects-part1/task-03.js new file mode 100644 index 0000000000..940f6099d5 --- /dev/null +++ b/src/ex3_js-objects-part1/task-03.js @@ -0,0 +1,10 @@ +function checkPropertyInObject(property, object) { + for (const key in object) { + if (property === key && object.hasOwnProperty(key)) { + return true; + } + } + return false; +} + +module.exports = checkPropertyInObject; diff --git a/src/ex3_js-objects-part1/task-04.js b/src/ex3_js-objects-part1/task-04.js new file mode 100644 index 0000000000..15170cc05e --- /dev/null +++ b/src/ex3_js-objects-part1/task-04.js @@ -0,0 +1,13 @@ +function addValueInObject(string, object) { + for (const key in object) { + if (string === key && object.hasOwnProperty(key)) { + return true; + } + } + + object[string] = 'new'; + + return object; +} + +module.exports = addValueInObject; diff --git a/src/ex3_js-objects-part1/task-05.js b/src/ex3_js-objects-part1/task-05.js new file mode 100644 index 0000000000..9aa6e154d1 --- /dev/null +++ b/src/ex3_js-objects-part1/task-05.js @@ -0,0 +1,5 @@ +function cloneObject(object) { + return { ...object }; +} + +module.exports = cloneObject; diff --git a/src/ex3_js-objects-part1/task-06.js b/src/ex3_js-objects-part1/task-06.js new file mode 100644 index 0000000000..a7b9dbfada --- /dev/null +++ b/src/ex3_js-objects-part1/task-06.js @@ -0,0 +1,12 @@ +function getProperty(object, propertyPath) { + let currentObject = object; + + for (const property of propertyPath.split('.')) { + if (currentObject == null) return undefined; + currentObject = currentObject[property]; + } + + return currentObject; +} + +module.exports = getProperty; diff --git a/src/ex3_js-objects-part1/task-07.js b/src/ex3_js-objects-part1/task-07.js new file mode 100644 index 0000000000..0da1dd1048 --- /dev/null +++ b/src/ex3_js-objects-part1/task-07.js @@ -0,0 +1,19 @@ +function deepCloneObject(object) { + const copyDeepObject = {}; + for (const key in object) { + if ( + typeof object[key] === 'object' + && object[key] !== null + && !(object[key] instanceof Array) + ) { + copyDeepObject[key] = deepCloneObject(object[key]); + } else if (object[key] instanceof Array) { + copyDeepObject[key] = object[key].slice(0); + } else { + copyDeepObject[key] = object[key]; + } + } + return copyDeepObject; +} + +module.exports = deepCloneObject; diff --git a/src/ex4_js-objects-part2/task-01.js b/src/ex4_js-objects-part2/task-01.js new file mode 100644 index 0000000000..e69de29bb2