File tree Expand file tree Collapse file tree 3 files changed +56
-0
lines changed
02-javascript-data-types/3-omit Expand file tree Collapse file tree 3 files changed +56
-0
lines changed Original file line number Diff line number Diff line change
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 )
Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments