function display_with_spaces(num) {
let str = String(num);
let left = str.length % 3;
let res = '';
let ind = 0;
if(left > 0) {
res = str.substr(ind, left) + ' ';
ind += left;
while(ind < str.length) {
res += str.substr(ind, 3);
if(str.length - ind > 3) res = res + ' ';
ind += 3;
}
}
else {
while(ind < str.length) {
res += str.substr(ind, 3);
if(str.length - ind > 3) res = res + ' ';
ind += 3;
}
}
return res;
}
let print = s => console.log(s);
let stud = [
{ name: "One", marks: [8, 10, 7, 5, 4] },
{ name: "Two", marks: [5, 2, 8, 5, 3] },
{ name: "Three", marks: [6, 9, 3, 6, 7] },
{ name: "Fore", marks: [1, 7, 8, 4, 10] },
{ name: "Five", marks: [5, 8, 6, 9, 3] },
];
let st_min = {...stud[0]}, st_max = {...stud[0]};
let av_min = av_max = st_min.marks.reduce((a, c) => a + c, 0) / st_min.marks.length;
for(let ob of stud) {
let av = ob.marks.reduce((a, c) => a + c, 0) / ob.marks.length;
if(av_min > av) {
st_min = {...ob}; av_min = av;
}
if(av_max < av) {
st_max = {...ob}; av_max = av;
}
}
print(st_min);
print(st_max);
let print = s => console.log(s);
let arr = [1,'3', 2, 3, {}, NaN, [2, 4, 5, []]];
arr = arr.flat(Infinity);
let sum = 0;
for(let el of arr) {
if(Number.isFinite(el)) sum += el;
}
print(sum);
let print = s => console.log(s);
let arr = [1, '3', 2, 3, {}, NaN, [2, 4, 5, [] ]];
let sum = arr.flat(Infinity).filter(el => Number.isFinite(el)).reduce((acc,el) => acc + el, 0);
print(sum);
let arr = [2,1,3,5,2,7,1,4];
let min = arr[0], max = arr[0];
for(let i of arr) {
if(min > i) min = i;
if(max < i) max = i;
}
console.log('Result is: ' + (max-min));
let print = s => console.log(s);
function remove_vowels(s) {
let res = '';
for(let i of s) {
if(i != 'a' && i != 'e' && i != 'i' && i != 'o' && i != 'u') res += i;
}
return res;
}
let str = 'Twinkle, twinkle, little star';
print(remove_vowels(str));
const arr = ['Jimmy', 'Rayn', 'Jack', 'Vladimir', 'joen'];
let res = arr.filter(el => /J/i.test(el[0]));
console.log(res);
let arr = ['Андрей', 'Алексей', 'Сергей', 'Антон', 'Матвей', 'Роман', 'Руслан'];
let arr2 = [27, 22, 38, 45, 51, 42, 19];
let res = [];
arr.map((el, i) => [arr[i], arr2[i]]).sort((min, max) => min[1] - max[1]).map(el => {
let ob = {};
ob[el[0]] = el[1];
res.push(ob);
});
console.log(res);
let arr = ['9', '7', 'q', 'q', '9'];
let res = [], count = 0;
for(let i = 0; i < arr.length; ++i) {
for(let j = 0; j < arr.length; ++j) {
if(arr[i] === arr[j]) ++count;
}
if(count > 1) res.push(arr[i]);
count = 0;
}
console.log(res);