7 kyu

Coding Meetup #5 - Higher-Order Functions Series - Prepare the count of languages

6,668 of 8,222PiotrBerebecki

Description:

You will be given an array of objects (associative arrays in PHP, table in COBOL, dictionaries in Python) representing data about developers who have signed up to attend the next coding meetup that you are organising.

Your task is to return an object (associative array in PHP, table in COBOL, dictionary in Python) which includes the count of each coding language represented at the meetup.

For example, given the following input array:

var list1 = [
  { firstName: 'Noah', lastName: 'M.', country: 'Switzerland', continent: 'Europe', age: 19, language: 'C' },
  { firstName: 'Anna', lastName: 'R.', country: 'Liechtenstein', continent: 'Europe', age: 52, language: 'JavaScript' },
  { firstName: 'Ramon', lastName: 'R.', country: 'Paraguay', continent: 'Americas', age: 29, language: 'Ruby' },
  { firstName: 'George', lastName: 'B.', country: 'England', continent: 'Europe', age: 81, language: 'C' },
];
list1 = [
    { 'firstName': 'Noah', 'lastName': 'M.', 'country': 'Switzerland', 'continent': 'Europe', 'age': 19, 'language': 'C' },
    { 'firstName': 'Anna', 'lastName': 'R.', 'country': 'Liechtenstein', 'continent': 'Europe', 'age': 52, 'language': 'JavaScript' },
    { 'firstName': 'Ramon', 'lastName': 'R.', 'country': 'Paraguay', 'continent': 'Americas', 'age': 29, 'language': 'Ruby' },
    { 'firstName': 'George', 'lastName': 'B.', 'country': 'England', 'continent': 'Europe', 'age': 81, 'language': 'C' },
    ]
$list1 = [
  [
    "first_name" => "Noah",
    "last_name" => "M.",
    "country" => "Switzerland",
    "continent" => "Europe",
    "age" => 19,
    "language" => "C"
  ],
  [
    "first_name" => "Anna",
    "last_name" => "R.",
    "country" => "Liechtenstein",
    "continent" => "Europe",
    "age" => 52,
    "language" => "JavaScript"
  ],
  [
    "first_name" => "Ramon",
    "last_name" => "R.",
    "country" => "Paraguay",
    "continent" => "Americas",
    "age" => 29,
    "language" => "Ruby"
  ],
  [
    "first_name" => "George",
    "last_name" => "B.",
    "country" => "England",
    "continent" => "Europe",
    "age" => 81,
    "language" => "C"
  ]
];
       01  List.
          03  ListLength      pic 9(3) value 4.
          03  dev1.
              05 FirstName    pic a(9)  value 'Noah'.
              05 LastName     pic x(2)  value 'M.'.
              05 Country      pic a(24) value 'Switzerland'.
              05 Continent    pic a(8)  value 'Europe'.
              05 Age          pic 9(3)  value 19.
              05 Language     pic a(10) value 'C'.
          03  dev2.
              05 FirstName    pic a(9)  value 'Anna'.
              05 LastName     pic x(2)  value 'R.'.
              05 Country      pic a(24) value 'Liechtenstein'.
              05 Continent    pic a(8)  value 'Europe'.
              05 Age          pic 9(3)  value 32.
              05 Language     pic a(10) value 'JavaScript'.
          03  dev3.
              05 FirstName    pic a(9)  value 'Ramon'.
              05 LastName     pic x(2)  value 'R.'.
              05 Country      pic a(24) value 'Paraguay'.
              05 Continent    pic a(8)  value 'Americas'.
              05 Age          pic 9(3)  value 99.
              05 Language     pic a(10) value 'Ruby'.
          03  dev4.
              05 FirstName    pic a(9)  value 'George'.
              05 LastName     pic x(2)  value 'B.'.
              05 Country      pic a(24) value 'England'.
              05 Continent    pic a(8)  value 'Europe'.
              05 Age          pic 9(3)  value 21.
              05 Language     pic a(10) value 'C'.

your function should return the following object (associative array in PHP, table in COBOL):

{ C: 2, JavaScript: 1, Ruby: 1 }
{ 'C': 2, 'JavaScript': 1, 'Ruby': 1 }
[
  "C" => 2,
  "JavaScript" => 1,
  "Ruby" => 1
]
      [['C', 2], ['JavaScript': 1], ['Ruby': 1]]

Notes:

  • The order of the languages in the object does not matter.
  • The count value should be a valid number.
  • The input array will always be valid and formatted as in the example above.




This kata is part of the Coding Meetup series which includes a number of short and easy to follow katas which have been designed to allow mastering the use of higher-order functions. In JavaScript this includes methods like: forEach, filter, map, reduce, some, every, find, findIndex. Other approaches to solving the katas are of course possible.

Here is the full list of the katas in the Coding Meetup series:

Coding Meetup #1 - Higher-Order Functions Series - Count the number of JavaScript developers coming from Europe

Coding Meetup #2 - Higher-Order Functions Series - Greet developers

Coding Meetup #3 - Higher-Order Functions Series - Is Ruby coming?

Coding Meetup #4 - Higher-Order Functions Series - Find the first Python developer

Coding Meetup #5 - Higher-Order Functions Series - Prepare the count of languages

Coding Meetup #6 - Higher-Order Functions Series - Can they code in the same language?

Coding Meetup #7 - Higher-Order Functions Series - Find the most senior developer

Coding Meetup #8 - Higher-Order Functions Series - Will all continents be represented?

Coding Meetup #9 - Higher-Order Functions Series - Is the meetup age-diverse?

Coding Meetup #10 - Higher-Order Functions Series - Create usernames

Coding Meetup #11 - Higher-Order Functions Series - Find the average age

Coding Meetup #12 - Higher-Order Functions Series - Find GitHub admins

Coding Meetup #13 - Higher-Order Functions Series - Is the meetup language-diverse?

Coding Meetup #14 - Higher-Order Functions Series - Order the food

Coding Meetup #15 - Higher-Order Functions Series - Find the odd names

Coding Meetup #16 - Higher-Order Functions Series - Ask for missing details

Functional Programming
Data Structures
Arrays
Fundamentals
Algorithms

Stats:

CreatedNov 13, 2016
PublishedNov 13, 2016
Warriors Trained10903
Total Skips144
Total Code Submissions22456
Total Times Completed8222
JavaScript Completions6668
PHP Completions244
Python Completions1409
COBOL Completions7
Total Stars129
% of votes with a positive feedback rating95% of 1274
Total "Very Satisfied" Votes1159
Total "Somewhat Satisfied" Votes103
Total "Not Satisfied" Votes12
Total Rank Assessments9
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • PiotrBerebecki Avatar
  • donaldsebleung Avatar
  • Chrono79 Avatar
  • albertogcmr Avatar
  • ejini战神 Avatar
  • akar-0 Avatar
  • glovastefan Avatar
  • dfhwze Avatar
Ad