Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Make a frequency table (histogram)

Post

Make a frequency table (histogram)

+3
−0

Challenge

Given an array in any suitable format, create a frequency table for it. i.e: Pair each unique element with the number of times it appears in the array.

You can return the frequency table as a list of pairs, hashmap/dictionary, output the pairs directly, etc.

Tests

{ 1 1 2 3 5 6 6 }           -> { { 1 2 } { 2 1 } { 3 1 } { 5 1 } { 6 2 } }
{ }                         -> { }
{ 1 6 7 1 2 6 6 1 53 4 10 } -> { { 1 3 } { 2 1 } { 4 1 } { 53 1 } { 6 3 } { 7 1 } { 10 1 } }
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

Empty arrays (1 comment)
Empty arrays
Lundin‭ wrote over 2 years ago

Given that many languages do not support empty arrays, then how to deal with the { } scenario in those languages?