π¦
Has Property
Has Propertyμ¬μ κ°μ²΄ +10pts
Problem
Write a function that checks if an object has a specific property.
Examples
Input:
hasProperty({a: 1}, "a")Output:
trueInput:
hasProperty({a: 1}, "b")Output:
falseExplanation
μ΄ λ¬Έμ λ **in μ°μ°μ**λ₯Ό μ¬μ©νμ¬ κ°μ²΄μ μμ±μ΄ μ‘΄μ¬νλμ§ νμΈνλ λ°©λ²μ νμ΅ν©λλ€. ## ν΅μ¬ κ°λ : μμ± μ‘΄μ¬ νμΈ κ°μ²΄μ νΉμ μμ±μ΄ μλμ§ νμΈνλ λ°©λ²μ μ¬λ¬ κ°μ§κ° μμ΅λλ€. ### λ°©λ² 1: in μ°μ°μ ```javascript key in obj ``` - μμλ μμ±λ νμΈ - κ°μ₯ κ°λ¨ν λ¬Έλ² ### λ°©λ² 2: hasOwnProperty ```javascript obj.hasOwnProperty(key) ``` - μ체 μμ±λ§ νμΈ (μμ μ μΈ) ### λ°©λ² 3: undefined λΉκ΅ (κΆμ₯νμ§...
View detailed explanation βKey Concepts
in μ°μ°μ hasOwnProperty μμ± νμΈ μμ μμ±
Time: O(1) Space: O(1)
solution.js
Ctrl + Enter
Run tests to see results here.