JS
challenger
JS
challenger
  • Getting Started
  • Overview
  • Random Challenge
  • Javascript Basics
  • Javascript Arrays
  • Javascript Objects
    • - Accessing object properties one
    • - Accessing object properties two
    • - Accessing object properties three
    • - Check if property exists in object
    • - Creating Javascript objects one
    • - Creating Javascript objects two
    • - Creating Javascript objects three
    • - Extract keys from Javascript object
    • - Sum object values
    • - Remove a property from an object
    • - Merge two objects with matching keys
    • - Multiply all object values by x
    • - Swap object keys and values
    • - Replace empty strings in object with null values
    • - Extracting information from objects
    • - Add property to each object in array
    • - Convert array to object with counter
  • Javascript Dates
  • Javascript Sets
  • Javascript DOM
    NEW
  • Challenge Rush
Imprint Privacy Policy

Convert array to object with counter

// Write a function that takes an array of numbers as argument
// Convert the array to an object
// It should have a key for each unique value of the array
// The corresponding object value should be the number of times the key occurs within the array
function
myFunction
(
a
)
{

return
}
Test Cases:
myFunction([1,2,2,3])
Expected
{1:1,2:2,3:1}
myFunction([9,9,9,99])
Expected
{9:3,99:1}
myFunction([4,3,2,1])
Expected
{1:1,2:1,3:1,4:1}
Twitter_Logo_White-on-Blue
Follow