Skip to content

Sporty Friends - array methods

webprogramming language-features arrays unit-test

Task location: tasks/language-features Test: global unit test

In a group of friends, many people enjoy sports and a lot of of them also do sports themselves. We know the following information about each person:

  • name: the person’s name (string)
  • age: the person’s age (number)
  • favSport: the person’s favorite sport (string), null if they do not have one
  • hasStrava: whether the person uses the Strava application (boolean)

Implement the taskA–taskH functions that solve the tasks below. The functions have the following format:

  • input: an array of people (array of objects)
  • return value: the answer to the corresponding subtask (it may be a number/string/boolean value)

For example:

// calculate the average age
const taskE = (friendsArray) => {
  // calculate the average age: avgAge
  // return avgAge
};

Starter package

The task description and starter files, ready to work on locally.

Included files: index.js

Tasks

taskA(friendsArray)

How many adults are there in the group?

taskB(friendsArray)

Determine whether there is anyone who does not have a favorite sport.

taskC(friendsArray)

Determine whether everyone uses Strava.

taskD(friendsArray)

Find the first person whose favorite sport is handball. If there is no such person, return null.

taskE(friendsArray)

Calculate the average age of the group of friends. Return 0 in case of empty input array!

taskF(friendsArray)

Return the name of the oldest person. Return null in case of empty input array!

taskG(friendsArray)

Collect the names of all people who do not have a favorite sport into an array!

taskH(friendsArray)

Sort the people by age in ascending order (sorting in place)!

Requirements

  • input: an array of people (array of objects)
  • return value: the answer to the corresponding subtask (it may be a number/string/boolean value)
  • Test: global unit test