-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
reverseKeyValue 함수 생성 (issue #15)
- Loading branch information
Showing
5 changed files
with
33 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './batchOfRequestOf'; | ||
export * from './reverseKeyValue'; |
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,13 @@ | ||
# reverseKeyValue | ||
|
||
객체의 Key, Value 값을 뒤바꿔서 리턴해주는 유틸 함수입니다. | ||
|
||
Key와 Value는 | ||
|
||
## - Example | ||
|
||
```ts | ||
const obj = { a: 1, b: 2 }; | ||
|
||
const result = reverseKeyValue(obj); // {1 : 'a', 2 : 'b'} | ||
``` |
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,13 @@ | ||
import { reverseKeyValue } from './reverseKeyValue'; | ||
|
||
describe('reverseKeyValue 유틸 함수에 대한 테스트 코드 작성', () => { | ||
it('객체의 key, value 값을 서로 뒤바꾸어서 반환해야한다.', () => { | ||
const obj = { a: 1, b: '2' }; | ||
|
||
const expectedObj = { 1: 'a', '2': 'b' }; | ||
|
||
const result = reverseKeyValue(obj); | ||
|
||
expect(result).toEqual(expectedObj); | ||
}); | ||
}); |
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,5 @@ | ||
export const reverseKeyValue = <Key extends string | number, Value extends string | number>( | ||
object: Record<Key, Value>, | ||
): Record<Value, Key> => { | ||
return Object.fromEntries(Object.entries(object).map(([key, value]) => [value, key])); | ||
}; |