-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
24 lines (24 loc) · 1013 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"use strict";
const STUDENT_OF_SCIENCE_CLUB = ['abc', 'cdf', 'efg', 'hij', 'klm'];
const STUDENT_OF_SPORTS_CLUB = ['nop', 'qrs', 'uvw', 'xyz', 'abc'];
function convertArrayToObject(studentsOfScienceClub) {
let mapOfScienceStudents = {};
for (let i = 0; i < studentsOfScienceClub.length; i++) {
if (!mapOfScienceStudents[studentsOfScienceClub[i]]) {
const student = studentsOfScienceClub[i];
mapOfScienceStudents[student] = true;
}
}
return mapOfScienceStudents;
}
function hasCommonStudentInBothClub(studentsOfScienceClub, studentsOfSportClub) {
let mapOfScienceStudents = convertArrayToObject(studentsOfScienceClub);
for (let i = 0; i < studentsOfSportClub.length; i++) {
if (mapOfScienceStudents[studentsOfSportClub[i]]) {
return true;
}
}
return false;
}
let hasCommonStudent = hasCommonStudentInBothClub(STUDENT_OF_SCIENCE_CLUB, STUDENT_OF_SPORTS_CLUB);
console.log(hasCommonStudent);