Skip to content

Commit 4d34923

Browse files
committed
Added task omit
1 parent 417693c commit 4d34923

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# omit
2+
3+
Необходимо реализовать функцию, которая на вход будет принимать объект и произвольное
4+
количество строк - ключей объекта:
5+
6+
```javascript
7+
const obj = {}
8+
9+
omit(obj, 'field-1', 'field-2', ...'field-n');
10+
```
11+
12+
а возвращать будет новый объект с полями которые не были перечислены при вызове функции
13+
14+
**Пример:**
15+
16+
```javascript
17+
const fruits = {
18+
apple: 2,
19+
orange: 4,
20+
banana: 3
21+
};
22+
23+
console.log(omit(fruits, 'apple', 'banana')); // Вернет объект - { orange: 4 }
24+
```
25+
26+
**Подсказка:** Обратите внимание на метод [Object.entries](https://learn.javascript.ru/keys-values-entries)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* omit - creates an object composed of enumerable property fields
3+
* @param {object} obj - the source object
4+
* @param {...string} fields - the properties paths to omit
5+
* @returns {object} - returns the new object
6+
*/
7+
export const omit = (obj, ...fields) => {
8+
9+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { omit } from './index';
2+
3+
describe('javascript-data-types/omit', () => {
4+
it('should return a new object without passed field', () => {
5+
const obj = {foo: 'foo'};
6+
7+
expect(omit(obj, 'foo')).toEqual({});
8+
});
9+
10+
it('should return a new object without few passed fields', () => {
11+
const obj = {foo: 'foo', bar: 'bar', baz: 'baz'};
12+
13+
expect(omit(obj, 'foo', 'bar')).toEqual({baz: 'baz'});
14+
});
15+
16+
it('should return initial object if passed fields doesn\'t found', () => {
17+
const obj = {foo: 'foo'};
18+
19+
expect(omit(obj, 'riba')).toEqual({foo: 'foo'});
20+
});
21+
});

0 commit comments

Comments
 (0)