var countStudents = function (students, sandwiches) {
let count = 0;
let availableStudent = students;
let availableSandwhich = sandwiches;
while (availableStudent.length !== count) {
const nextStudent = availableStudent.shift();
const nextSandwich = availableSandwhich.shift();
if (nextStudent === nextSandwich) {
count = 0;
} else {
count++;
availableSandwhich.unshift(nextSandwich);
availableStudent.push(nextStudent);
}
}
return count;
};
var countStudents = (students, sandwiches) => {
while (students.length) {
if (students[0] === sandwiches[0]) {
students.shift();
sandwiches.shift();
}
else if (!students.includes(sandwiches[0]))
return students.length;
else students.push(students.shift());
}
return 0;
};
Top comments (0)