const myMath = {
minNum(...num) {
if (!num.length) {
return console.log(`введите данные`);
}
num = num.filter(num => !isNaN(num - parseFloat(num)));
if (!num.length) {
return console.log(`введите пжл число`);
}
let min = num[0];
for (let i = 1; i < num.length; i++) {
if (num[i] < min) {
min = num[i];
}
}
console.log(`минимальное число ${min}`);
}
}
myMath.minNum('1', 2, -1); // минимальное число -1
myMath.minNum('строка'); // введите пжл число
myMath.minNum(); // введите данные
for (let i = 0; i < dataExample.length; i++) {
document.body.insertAdjacentHTML('beforeend', dataExample[i].company + '<br>');
document.body.insertAdjacentHTML('beforeend', dataExample[i].chef + '<br>');
document.body.insertAdjacentHTML('beforeend', dataExample[i].country + '<br>');
}
function date_time() {
return new Intl.DateTimeFormat('en', {
hour12: false,
day: 'numeric',
month: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
timeZone: 'Europe/Moscow'
}).format(Date.now())
}
date_time(); // "12/29/2020, 08:03:23"
date_time().replace(',', ' Ortszeit:');// "12/29/2020 Ortszeit: 08:03:23"
history.pushState(null, null, location.href.replace('#', ''));
document.querySelector('.close').addEventListener('click', event => event.preventDefault());
["5", "0", "1jj" ].filter(v => !isNaN(parseFloat(v)));
//["5", "0", "1jj1"]
["5", "0", "1jj1" ].filter(num => !isNaN(num - parseFloat(num)));
//["5", "0"]
["5", "0", "jj1" ].filter(Number);
//["5"]
const statuses_default = {
"Logon": {
"order": 1,
"data": {}
},
"Ready": {
"order": 3,
"data": {}
},
"Not Ready": {
"order": 2,
"data": {}
},
"Logoff": {
"order": 0,
"data": {}
}
}
let res = Object.entries(statuses_default).sort((a, b) => a[1].order - b[1].order);
console.log(res)
<form>
<input id="product_preview183" name="variant" value="183" type="radio" class="sytle-input" checked="">
<input class="amounts incr__val" name="add_variant[107]" type="text" value="0">
<input class="amounts incr__val" name="add_variant[108]" type="text" value="2">
<button type="submit" value="">Добавить</button>
</form>
let form = $('form');
let data = form.serializeArray().filter(item => +item.value);//фильтрация подойдет если в value будут цифры, иначе поменять нужно условие
console.log(data );
/*
[
{name: "variant", value: "183"},
{name: "add_variant[108]", value: "2"}
]
*/
// после data передаем в аякс
document.querySelectorAll('.hello').forEach(item => {
item.querySelector('a');
})
[...document.querySelector('.hello').children].forEach(item => {})
let userList = '';
const myAjax = (url, method = 'GET', headers = {}) => {
return new Promise(resolve => {
$.ajax({
method: method,
url: url,
headers: headers,
dataType: 'json',
success: resolve,
});
})
}
(async () => {
let data = await myAjax("https://jsonplaceholder.typicode.com/todos/");
userList = data;
console.log(userList);
})()
var info = [{
desc: 'elem',
number: 10,
}, {
desc: 'elem2',
number: 20,
}, {
sum: 200,
}];
var sum = info.filter(i => i.sum).shift().sum;
var res = info.filter(i => i.number).map(m => (m.number / sum) * 100);
console.log(res);// [5, 10]
[1,"", null, NaN, 2, undefined,4,5,6].filter(Boolean); //[1, 2, 4, 5, 6]
[{
desc: 'elem',
number: 10,
}, {
desc: 'elem2',
number: 12,
}, {
count: 300,
}].filter(i => i.number).map( m => m.number); // [10, 12]
prompt
не работает. Количество пробелов:let myStr = prompt("text some...");
console.log(myStr.split(" ").length-1)
let myStr = prompt("text some...");
console.log(myStr.match(/\s/g).length)