const songsNames = [
'sokol_in.mp3',
'turtle_in.mp3',
'wolf_in.mp3',
'bear_in.mp3'
];
let audio = new Audio('sokol_in.mp3');
$('.select > div').on('click', () => {
const index = Number($(this).attr('data-val'));
audio = new Audio(songsNames[index]);
});
document.getElementById('play').addEventListener('click', () => audio.pause());
audio
, которая уничтожается при выходе из условного оператора. function filter(array = [], filters = {}) {
const keys = Object.keys(filters).filter(key => filters.hasOwnProperty(key));
return array.filter(elem => {
const commonKeys = keys.filter(key => elem.hasOwnProperty(key));
return commonKeys.reduce((flag, key) => (flag && filters[key].includes(elem[key])), true);
});
}
filters
кладёте допустимые значения по соответствующим ключам. Например:const products = [
{country: 'Russia', img: 'link.img', genre: 'Comedy', name: 'Вишнёвый сад'},
{country: 'France', img: 'link.img', genre: 'Novel', name: 'Oberman'},
{country: 'Italy', img: 'link.img', genre: 'Adventures', name: 'Il cimitero di Praga'},
{country: 'USA', img: 'link.img', genre: 'Comedy', name: 'The Ransom of Red Chief'}
];
const filters = {
country: ['Russia', 'Italy', 'France'],
genre: ['Comedy', 'Novel']
};
const filteredProducts = filter(products, filters);
($(element) as any).keydown(e => {
const {
target: {
selectionStart,
selectionEnd
},
keyCode: direction
} = e;
const htmlNode = $(this);
const inputValue = htmlNode.val();
const splittedTime = splitTime(inputValue);
const selectedValue = inputValue.substring(selectionStart, selectionEnd);
if (!selectedValue) { return; }
const Point = (x, y) => ({x, y});
const points = [Point(0, 2), Point(3, 5), Point(6, 10)];
const targetPoint = Point(selectionStart, selectionEnd);
const LEFT = 37;
const UP = 38;
const RIGHT = 39;
const DOWN = 40;
if ((direction === LEFT) || (direction === RIGHT)) {
e.preventDefault();
const index = points.findIndex(p => ((p.x === targetPoint.x) && (p.y === targetPoint.y)));
if (index === -1) { return; }
index += ((direction === LEFT) ? points.length : 1);
points.push(targetPoint);
const point = points[index % points.length];
this.setSelectionRange(point.x, point.y);
}
if ((direction === DOWN) || (direction === UP)) {
e.preventDefault();
const Actions = Enums.ValueActions;
const action = ((direction === DOWN) ? Actions.decrement : Actions. increment);
changeAppendix(splittedTime, selectedValue, htmlNode);
adjustTime(splittedTime, htmlNode, action, selectionStart, selectedValue);
this.setSelectionRange(selectionStart, selectionEnd);
}
});
['first', 'last'].forEach(term => {
jQuery(val).each((index, value) => {
const elem = jQuery(value).find(`.woocommerce-Price-amount.amount:${term}`);
let price = elem.attr('data-orig-price') / data;
price = ((valute_text === '₽')
? price.toFixed(0).toString().replace(/(\d)(?=(\d{3})+([^\d]|$))/g, '$1 ')
: price.toFixed(2));
elem.text(price + valute_text);
});
});
let temp = document.getElementById('js');
temp.innerHTML = (`
<div class="block">
<span>1</span>
<span>2</span>
<span>3</span>
</div>
`);
const tableRow = ({id, name, token, owner_id}) => (`
<tr id="${id}" class="table-activate">
<td scope="col">${id}</td>
<td scope="col">${name}</td>
<td scope="col">${token}</td>
<td scope="col">${owner_id}</td>
</tr>
`);
const tableBody = data => data.reduce((body, elem) => (body + tableRow(elem)), '');
content.append(`
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
${tableBody(data)}
</tbody>
`);
function convertText(str, key) {
key = (26 - key) % 26;
return [...str].map(symb => {
const code = symb.charCodeAt(0);
let shift = 0;
if ((65 <= code) && (code <= 90)) {
shift = 65;
} else if ((97 <= code) && (code <= 122)) {
shift = 97;
}
if (shift > 0) {
return String.fromCharCode(shift + ((code - shift + key) % 26));
} else {
return symb;
}
}).join('');
}
alert(convertText('Hmjw uzsfuw dwv eq xjawfv Zwjumdw Hgajgl, xgjewjdq uzawx gx lzw Twdyasf xgjuw, lg tw ugffwulwv oalz lzw Klqdwk uskw', 18));
S = b = a / sqrt(N)
const s = "Destiny\s Child";
s.replace(/(s )/g, "'s ");