RUSNORD,
<pre id="out"></pre>
<script>
let a = ["a", "e", "i", "o", "u", "y"]
let b = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "z"]
function random(min, max, arr) {
if (arr) {
min = 0;
max = arr.length - 1
}
return function() {
let index = min + Math.floor(Math.random() * (max - min + 1));
return arr ? arr[index] : index
}
}
function createNik() {
let length = random(3, 7)(),
a_r = random(0, 0, a),
b_r = random(0, 0, b),
k = +(Math.random() > .5),
nik = (k ? a_r() : b_r()).toUpperCase();
for (let i = 1; i < length; i++) {
nik += (i % 2 !== k) ? a_r() : b_r()
}
return nik
}
function createRating() {
let rating = random(0, 0, [5, 5, 3, 5, 4, 5, 4, 4, 4, 5, 5, 2, 5, 5]),
length = 5;
return Array.from({
length
}, _ => rating())
}
let testScill = [{
fn: a => a.every(e => e === 5),
name: "Отличник"
}, {
fn: a => a.every(e => [5, 4].includes(e)),
name: "Хорошист"
}, {
fn: a => a.some(e => e === 2),
name: "Неуспевающий"
}];
function _skill(arr) {
for (let {
fn,
name
} of testScill) {
if (fn(arr)) return name;
};
return '---'
}
function listOfStudents() {
let length = random(3, 15)();
return Array.from({
length
}, _ => {
let rating = createRating(),
nik = createNik(),
scill = _skill(rating);
return {
nik,
rating,
scill
}
})
}
let students = listOfStudents();
out.append(JSON.stringify(students, function(key, value) {
if (key === 'rating') {
return value.toString();
}
return value;
}, 1))
function searchScill(patern)
{
return students.filter(({scill}) => scill === patern).map(({nik}) => nik)
}
let listOfFailing = searchScill("Неуспевающий");
out.append(`\n${listOfFailing.length} underachievers : ${listOfFailing}`);
let listOfGood = searchScill("Хорошист");
out.append(`\n${listOfGood.length} goods : ${listOfGood}`);
let listOfExcellent = searchScill("Отличник");
out.append(`\n${listOfExcellent.length} excellents : ${listOfExcellent}`);
</script>