Day 85: Count Value Occurrences in an Object | 100 Days of JavaScript Coding Challenge

Опубликовано: 13 Январь 2025
на канале: Code with Poonam
39
4

🎯 Welcome to Day 85 of the 100 Days of JavaScript Coding Challenge! 🚀
#CodeWithPoonam #100DaysOfCode

📥 Problem Statement:
Write a JavaScript function to count how many times each value appears in an object.

📊 Example:

Input:
{ a: 1, b: 2, c: 1, d: 3, e: 2 }
Output: { 1: 2, 2: 2, 3: 1 }

Input:
{ a: "apple", b: "banana", c: "apple", d: "grape" }
Output: { apple: 2, banana: 1, grape: 1 }

Input:
{ a: true, b: false, c: true, d: true }
Output: { true: 3, false: 1 }

💡 Approach:
✅ Step 1: Extract values using Object.values().
✅ Step 2: Initialize an empty object to store the counts.
✅ Step 3: Use a for...of loop to iterate through the values.
✅ Step 4: Increment the count for each value or initialize it if not present.
✅ Step 5: Return the count object showing the frequency of each value.

📚 Key Concepts Used:
✅ Object.values(): Extracts the values from an object.
✅ for...of: Loops through iterable values.
✅ Counting Logic: Using (count[value] || 0) + 1.

📅 On Day 85, you learned how to count the frequency of values in an object using JavaScript's Object.values() and a for...of loop.

🔥 Keep coding and stay consistent!
📩 #JavaScript #CodingChallenge #100DaysOfCode #CodeWithPoonam #learnjavascript

javascript coding challenge, javascript Coding Challenge Interview Questions 2024, javascript coding interview, javascript array interview questions answers, javascript reduce interview questions, javascript coding questions, javascript coding challenges for beginners, javascript coding examples, javascript interview coding exercises, javascript interview questions and answers for experienced and freshers.#javascriptcoding
javascript coding challenge, javascript Coding Challenge Interview Questions 2024, javascript coding interview, javascript array interview questions answers, javascript strings interview questions answers, javascript object interview questions answers, javascript math interview questions, javascript reduce interview questions, javascript coding interview questions and answers, javascript coding for beginners, javascript coding questions, javascript coding challenges for beginners, javascript coding examples, javascript interview coding exercises, javascript interview questions and answers for experienced and freshers.

Javascript interview questions and answers, javascript interview questions, javascript interview coding exercises, javascript interview questions and answers 2024, javascript interview questions and answers 2023, javascript interview prep, javascript in 12 minutes.