Веселые конкурсы.
function jsConfig() {
const str1 = 'AjacJJvas 11 c pp ri fascd ript';
const str2 = 'JavaScript';
const res1 = str1.toLowerCase().split('');
const res2 = [];
res1.forEach((e,i,a) => {
if ((str2.toLowerCase().includes(e) && !res2.includes(e)) ||
(e === 'a' && res2.join().match(/a/gi).length < 2 )) res2.push(e);
if (res2.length === str2.length) {
console.log(`Исходная строка: ${str1}\nИзмененная строка: ${str2}`);
} else if (i === a.length-1) {
console.log(`Нужные символы не были найдены!`);
}
})
}
jsConfig();
function zooHuman(age,height,sum) {
age = !age ? +prompt('Ваш возраст:') : age;
if (!isNaN(age)) {
height = !height ? +prompt('Ваш рост:') : height;
if (!isNaN(height)) {
sum = age + height;
console.log(sum);
if (sum > 180) console.log('Жираф');
else if (sum < 180) console.log('Крокодил');
else console.log('Фламинго');
} else {
zooHuman(age,0);
}
} else {
zooHuman(0,height);
}
}
zooHuman();
function winNumbers() {
const viewer = confirm('Хотите узнать победителя?');
if (viewer) {
const arr1 = [51,301,311,103];
const arr2 = [41,151,430,100];
const res1 = arr1.reduce((a,b) => a += b);
const res2 = arr2.reduce((a,b) => a += b);
const res3 = res1 - res2;
if (res3 > 0) {
console.log(`С разницей в ${Math.abs(res3)} победил первый массив: [${arr1}]`);
} else {
console.log(`С разницей в ${Math.abs(res3)} победил второй массив: [${arr2}]`);
}
} else {
alert('Ну и ладно!')
}
}
winNumbers();