📦

Invert Object

Invert Object
쉬움 객체 +10pts

Problem

Write a function that swaps the keys and values of an object.

Examples

Input: invert({a: "1", b: "2"})
Output: {"1": "a", "2": "b"}

Explanation

이 문제는 **Object.entries**와 **Object.fromEntries**를 활용한 객체 변환을 학습합니다. **객체 ↔ 배열 변환** - `Object.entries(obj)`: 객체 → [key, value] 배열들의 배열 - `Object.fromEntries(arr)`: [key, value] 배열들 → 객체 **알고리즘 단계** 1. entries로 [key, value] 쌍들의 배열로 변환 2. map으로 각 쌍을 [value, key]로 뒤집기 3. fromEntries로 다시 객체로 변환 **{a: ...

View detailed explanation →

Key Concepts

Object.entries Object.fromEntries 구조 분해 할당 키-값 교환
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.