Skip to content
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

Patch 1 #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions 01-javascript-data-types/1-sort-strings/solution/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* sortStrings - sorts array of string by two criteria "asc" or "desc"
* @param {string[]} arr - the array of strings
* @param {string} [param="asc"] param - the sorting type "asc" or "desc"
* @returns {string[]}
*/
export function sortStrings(arr, param = 'asc') {
switch (param) {
case 'asc':
return makeSorting(arr, 1);
case 'desc':
return makeSorting(arr, -1);
default:
return makeSorting(arr, 1);
}

function makeSorting(array, direction) {
return [...array].sort((a, b) =>
direction * a.localeCompare(b, 'default', {caseFirst: 'upper'}));
}
}
17 changes: 17 additions & 0 deletions 01-javascript-data-types/2-pick/solution/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* pick - Creates an object composed of the picked object properties:
* @param {object} obj - the source object
* @param {...string} fields - the properties paths to pick
* @returns {object} - returns the new object
*/
export const pick = (obj, ...fields) => {
const result = {};

for (let [key, value] of Object.entries(obj)) {
if (fields.includes(key)) {
result[key] = value;
}
}

return result;
};
17 changes: 17 additions & 0 deletions 01-javascript-data-types/3-omit/solution/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* omit - creates an object composed of enumerable property fields
* @param {object} obj - the source object
* @param {...string} fields - the properties paths to omit
* @returns {object} - returns the new object
*/
export const omit = (obj, ...fields) => {
const result = {};

for (let [key] of Object.entries(obj)) {
if (!fields.includes(key)) {
result[key] = obj[key];
}
}

return result;
};
22 changes: 22 additions & 0 deletions 02-objects-arrays-intro-to-testing/1-create-getter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# createGetter

Необходимо реализовать функцию "createGetter". Функция должна принимать строку вида
"prop-1.prop-2.prop-n", где "prop-1, ..., prop-n" - это свойства объекта разделенные точкой.
Возвращать "createGetter" должна новую функцию, которая по заданному пути
найдет значение в переданном ей объекте и вернет его.

```javascript
function createGetter(field) {
/* ... */
}

const product = {
category: {
title: "Goods"
}
}

const getter = createGetter('category.title');

console.log(getter(product)); // Goods
```
8 changes: 8 additions & 0 deletions 02-objects-arrays-intro-to-testing/1-create-getter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* createGetter - creates function getter which allows select value from object
* @param {string} path - the strings path separated by dot
* @returns {function} - function-getter which allow get value from object by set path
*/
export function createGetter(path) {

}
59 changes: 59 additions & 0 deletions 02-objects-arrays-intro-to-testing/1-create-getter/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { createGetter } from './index.js';

describe('objects-arrays-intro-to-testing/create-getter', () => {
it('should return existed properties', () => {
const obj = {
category: {
title: 'Goods',
foo: undefined
}
};
const getter = createGetter('category.title');

expect(getter(obj)).toEqual('Goods');
});

it('should return "undefined" for properties which does not exist', () => {
const obj = {
category: {
title: 'Goods',
foo: undefined
}
};
const getter1 = createGetter('category.foo');
const getter2 = createGetter('category.bar');

expect(getter1(obj)).toBeUndefined();
expect(getter2(obj)).toBeUndefined();
});

it('gets obj.property', () => {
const getter = createGetter('property');

expect(getter({property: 1})).toEqual(1);
});

it('returns undefined for no property', () => {
const getter = createGetter('property');

expect(getter({})).toBeUndefined();
});

it('gets obj.nested.property', () => {
const getter = createGetter('nested.property');

expect(getter({nested: {property: 1}})).toEqual(1);
});

it('returns undefined for no nested.property', () => {
const getter = createGetter('nested.property');

expect(getter({})).toBeUndefined();
});

it('gets more.nested.property', () => {
const getter = createGetter('more.nested.property');

expect(getter({more: {nested: {property: 1}}})).toEqual(1);
});
});
12 changes: 12 additions & 0 deletions 02-objects-arrays-intro-to-testing/2-invert-object/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# invertObj

Необходимо реализовать функцию, которая меняет местами ключи и значения в объекте.
Функция принимает объект, свойства которого могут быть только примитивными значениями,
а возвращает новый объект, где ключи и свойства заменены между собой местами.

**Пример:**
```javascript
const obj = { key: 'value' };

console.log(invertObj(obj)); // { value: 'key'}
```
8 changes: 8 additions & 0 deletions 02-objects-arrays-intro-to-testing/2-invert-object/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* invertObj - should swap object keys and values
* @param {object} obj - the initial object
* @returns {object | undefined} - returns new object or undefined if nothing did't pass
*/
export function invertObj(obj) {

}
25 changes: 25 additions & 0 deletions 02-objects-arrays-intro-to-testing/2-invert-object/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { invertObj } from './index.js';

describe('objects-arrays-intro-to-testing/invert-object', () => {
it('should swap keys and values and return new object', () => {
const obj = {
key1: 'value1',
key2: 'value2'
};

const expected = {
value1: 'key1',
value2: 'key2',
};

expect(invertObj(obj)).toEqual(expected);
});

it('should return empty object if was passed object without values', () => {
expect(invertObj({})).toEqual({});
});

it('should return "undefined" if object wasn\'t passed', () => {
expect(invertObj()).toBeUndefined();
});
});
18 changes: 18 additions & 0 deletions 02-objects-arrays-intro-to-testing/3-trim-symbols/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# trimSymbols

Необходимо реализовать функцию "trimSymbols". Функция принимает 2 аргумента:
1. строку произвольной длинны
2. число разрешенных одинаковых символов которые расположены в строке подряд

Функция должна вернуть строку символов, удалив из нее все последовательные одинаковые
символы которые превышают заданное число.

**Пример:**

```javascript
trimSymbols('xxx', 3); // 'xxx' - ничего не удалили т.к разрешено 3 символа подряд
trimSymbols('xxx', 2); // 'xx' - удалили один символ
trimSymbols('xxx', 1); // 'x'

trimSymbols('xxxaaaaa', 2); // 'xxaa'
trimSymbols('xxxaaaaab', 3); // 'xxxaaab'
9 changes: 9 additions & 0 deletions 02-objects-arrays-intro-to-testing/3-trim-symbols/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* trimSymbols - removes consecutive identical symbols if they quantity bigger that size
* @param {string} string - the initial string
* @param {number} size - the allowed size of consecutive identical symbols
* @returns {string} - the new string without extra symbols according passed size
*/
export function trimSymbols(string, size) {

}
21 changes: 21 additions & 0 deletions 02-objects-arrays-intro-to-testing/3-trim-symbols/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { trimSymbols } from './index.js';

describe('objects-arrays-intro-to-testing/trim-symbols', () => {
it('should remove an identical consecutive characters that exceed the specified size', () => {
expect(trimSymbols('eedaaad', 2)).toEqual('eedaad');
expect(trimSymbols('xxx', 1)).toEqual('x');
expect(trimSymbols('xxxaaaaab', 1)).toEqual('xab');
});

it('should return empty string if it was passed to function like an argument', () => {
expect(trimSymbols('', 2)).toEqual('');
});

it('should return empty string if "size" equal 0', () => {
expect(trimSymbols('accbbdd', 0)).toEqual('');
});

it('should return the same string if "size" parameter wasn\'t specified', () => {
expect(trimSymbols('aaa')).toEqual('aaa');
});
});
11 changes: 11 additions & 0 deletions 02-objects-arrays-intro-to-testing/4-uniq/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# uniq

Необходимо реализовать функцию "uniq".
Функция принимает один аргумент - массив примитивных значений и возвращает
новый массив уникальных значений

**Пример:**
```javascript
uniq([1, 2, 2, 3, 1, 4]); // [1, 2, 3, 4]
uniq(['a', 'a', 'b', 'c', 'c']); // ['a', 'b', 'c']
```
8 changes: 8 additions & 0 deletions 02-objects-arrays-intro-to-testing/4-uniq/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* uniq - returns array of uniq values:
* @param {*[]} arr - the array of primitive values
* @returns {*[]} - the new array with uniq values
*/
export function uniq(arr) {

}
16 changes: 16 additions & 0 deletions 02-objects-arrays-intro-to-testing/4-uniq/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { uniq } from './index.js';

describe('objects-arrays-intro-to-testing/uniq', () => {
it('should return array with uniq values', () => {
expect(uniq([1, 1])).toEqual([1]);
expect(uniq([1, 'a', 'a', 2, 2])).toEqual([1, 'a', 2]);
});

it('should return empty array if was passed array without values', () => {
expect(uniq([])).toEqual([]);
});

it('should return empty array if arguments wasn\'t passed', () => {
expect(uniq()).toEqual([]);
});
});
30 changes: 30 additions & 0 deletions 02-objects-arrays-intro-to-testing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Объекты и массивы, основы тестирования

## Материалы из учебника:

### [Типы данных](https://learn.javascript.ru/data-types)
- [Map и Set](https://learn.javascript.ru/map-set)
- [Object.keys, values, entries](https://learn.javascript.ru/keys-values-entries)
- Задача: [Сумма свойств объекта](https://learn.javascript.ru/task/sum-salaries)
- Задача: [Подсчёт количества свойств объекта](https://learn.javascript.ru/task/count-properties)
- [Деструктурирующее присваивание](https://learn.javascript.ru/destructuring-assignment)
- Задача: [Деструктурирующее присваивание](https://learn.javascript.ru/task/destruct-user)
- Задача: [Максимальная зарплата](https://learn.javascript.ru/task/max-salary)

### [Объекты: основы](https://learn.javascript.ru/object-basics)
- [Сборка мусора](https://learn.javascript.ru/garbage-collection)
- [Тип данных Symbol](https://learn.javascript.ru/symbol)
- [Методы объекта, "this"](https://learn.javascript.ru/object-methods)
- Задача: [Создайте калькулятор](https://learn.javascript.ru/task/calculator)
- [Преобразование объектов в примитивы](https://learn.javascript.ru/object-toprimitive)
- [Конструкторы, создание объектов через "new"](https://learn.javascript.ru/constructor-new)

### [Основы JavaScript](https://learn.javascript.ru/first-steps)
- [Функции-стрелки, основы](https://learn.javascript.ru/arrow-functions-basics)

### [Качество кода](https://learn.javascript.ru/code-quality)
- [Автоматическое тестирование c использованием фреймворка Mocha](https://learn.javascript.ru/testing-mocha)

## Дополнительные материалы:

* [Jest документация](https://jestjs.io/)
5 changes: 5 additions & 0 deletions 02-objects-arrays-intro-to-testing/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE html>

<script>

</script>
15 changes: 15 additions & 0 deletions 02-objects-arrays-intro-to-testing/module-plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Plan for Module #9

## Проверка ДЗ

* sortStrings
* pick
* omit

## Новая тема - Объекты и массивы, основы тестирования

* тесты - введение
* JS модули
* объекты, массивы

## Разбор нового ДЗ
2 changes: 0 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,3 @@

"01-javascript-data-types" - это имя директории модуля
"1-sort-strings" - имя директории задачи

test