The School of Langauge and Science teaches five subjects: Physics, Chemistry, Math, Botany, and Zoology. each student is skilled in one subject. The skills of the students are desccribed by string of a=named skills that consists of the letters p,c,m,b, abd z only. Each character describes the skill of a student.

Given a list of students' skills, determine the total number of different teams satisfying the following constrains:

A team consists of a group of exactly five students.

Each student is skilled in a different subject.

A student may only be on one team.

Example 1

skills = pcmbzpcmbz

There are 2 possible teams that can be formed at one time: skills[0-4] = pcmbz and skills[5-9] = pcmbz, for example.

Example 2

skills = mppzombpzcmpmzz

The sorted string is bbbbcccmmmmppppzzzz. All of the skills are represented, but there are only 3 students skilled in Chemistry. Only 3 teams can be created.

Function Description

Complete the function differentTeams in the editor below. The function must return an integer value representing the number of teams that can be formed given the constraints. differentTeams has the following parameter(s): string skills: a string of length n where each position represents the Skill of a student.

My Solution:

function perfectTeam(skills) {

let unique = new Set(skills);

if([...unique].sort().join('') !== 'bcmpz') {

return 0;

}

let counter = {};

[...skills].forEach(v => {

counter[v] ? counter[v]++ : counter[v] = 1;

});

return Object.values(counter).sort((a,b) => a-b)[0];

}