const data = [
'eur 10', 'rub 50', 'eur 5', 'rub 10', 'rub 10', 'eur 100', 'rub 200',
];
const money1 = [
'eur 10', 'usd 1', 'usd 10', 'rub 50', 'usd 5',
];
const money2 = [
'eur 10', 'usd 1', 'eur 5', 'rub 100', 'eur 20', 'eur 100', 'rub 200',
];
const getTotalAmount = (items, currency) => {
let arrays = [];
const a = [];
let sum = 0;
for(const item of items) {
const val = item.slice(0,3);
if(val === currency) {
arrays.push(item);
}
}
const res = arrays.map(el => {
const newValue = el.split(' ');
for(let i = 0; i < newValue.length; i++) {
let digit = parseInt(newValue[i]);
//вместо управляющей инструкции мы сделали это
if(!isNaN(digit)) {
a.push(newValue[i]);
}
}
});
for(const el of a) {
sum += +el
}
return sum;
};
console.log(getTotalAmount(data, 'rub'));
console.log(getTotalAmount(money1, 'usd'));
console.log(getTotalAmount(money2, 'eur'));
<?php $uri = $_SERVER["REQUEST_URI"];?>
<a href="/admin/index.php" <?php if ($uri == "/admin/index.php") {echo 'class="active"';}?>>Главная</a>
<a href="/admin/or.php" <?php if ($uri == "/admin/or.php") {echo 'class="active"';}?>>Заказы</a>
<a href="/admin/st.php" <?php if ($uri == "/admin/st.php") {echo 'class="active"';}?>>Статистика</a>
// скрипт в шапке
jQuery(document).ready(function( $ ) {
// код моего скрипта
});
$(function () {
// код моего скрипта
});
// скрипт в шапке
jQuery(document).ready(function( $ ) {
// код моего скрипта
});
//E-mail Ajax Send
$("form").submit(function() { //Change
var th = $(this);
$.ajax({
type: "POST",
url: "mail.php", //Change
data: th.serialize()
}).done(function() {
$(".js-modal, .js-overlay").fadeIn(500);
$("body").addClass("open-modal");
setTimeout(function() {
// Done Functions
th.trigger("reset");
}, 1000);
});
return false;
});
/* Modals
====================================*/
/*$(".js-show-modal").on("click", function() {
$(".js-modal, .js-overlay").fadeIn(500);
$("body").addClass("open-modal");
});*/
$(".js-overlay, .js-modal-close").on("click", function(e){
e.preventDefault();
$(".js-modal, .js-overlay").fadeOut();
$("body").removeClass("open-modal");
});