📦

Pick Object Keys

Pick Object Keys
쉬움 객체 +10pts

Problem

Write a function that creates an object with only the specified keys.

Examples

Input: pick({a: 1, b: 2, c: 3}, ["a", "c"])
Output: {a: 1, c: 3}

Explanation

이 문제는 **객체에서 원하는 속성만 추출**하는 pick 유틸리티 함수를 구현합니다. Lodash의 _.pick과 같은 기능입니다. **알고리즘 전략** 1. 빈 객체로 시작 2. 원하는 키 목록을 순회 3. 각 키가 원본 객체에 존재하면 복사 **reduce로 객체 생성** ```javascript keys.reduce((result, key) => { if (key in obj) result[key] = obj[key]; return result; }, {}); ``` **{a:1, b:2, c:3}에서 ["a",...

View detailed explanation →

Key Concepts

pick 유틸리티 reduce로 객체 생성 in 연산자 속성 필터링
Time: O(k) Space: O(k)
solution.js
Ctrl + Enter
Run tests to see results here.