function findSequence(input) {
const adjacencyList = {}, indegree = {};
input.forEach(([from, to]) => {
adjacencyList[from] = (adjacencyList[from] || []).concat(to);
indegree[to] = (indegree[to] || 0) + 1;
});
const start = Object.keys(adjacencyList).find(country => !indegree[country]);
if (!start) {
return false;
}
const result = [], visited = {};
function dfs(node) {
visited[node] = true;
result.push(node);
adjacencyList[node]?.forEach(neighbor => !visited[neighbor] && dfs(neighbor));
}
dfs(start);
return result.join(', ');
}
findSequence([["USA", "BRA"], ["JPN", "PHL"], ["BRA", "UAE"], ["UAE", "JPN"]])//"USA, BRA, UAE, JPN, PHL"
<div class="menu">menu 1</div>
<div class="menu">menu 2</div>
<div class="menu">menu 3</div>
<div class="menu">menu 4</div>
<div class="menu">menu 5</div>
Array.from(document.querySelectorAll('.menu'), node => node.textContent);
//["menu 1","menu 2","menu 3","menu 4","menu 5"]
<li class="collapsable" id="bx_1847241719_4017">
<div class="hitarea collapsable-hitarea">
</div>
<label>
<input type="checkbox" name="category[]" id="4017" value="4017"> Родитель
</label>
<ul id="tree-checkbox" class="treeview" style="display: block;">
<li id="bx_1847241719_4031"><label><input type="checkbox" name="category[]" id="4031" value="4031"> Раздел 1</label></li>
<li id="bx_1847241719_4030" class="last"><label><input type="checkbox" name="category[]" id="4030" value="4030"> Раздел 2</label></li>
</ul>
</li>
document.querySelector('#bx_1847241719_4017').addEventListener('click', function(e) {
e.target.closest('li').querySelectorAll('ul input[type=checkbox]').forEach( item => {
item.checked = e.target.checked;
})
})
let obj = {}
$('input[name="options[]"]:checked').each(function(){
obj[$(this).val()] = $(this).next('label').text()
});
function calculateFoodOrder(numAnimals = 0, avgFood = 0) {
if(Number.isInteger(numAnimals) && Number.isInteger(avgFood) && numAnimals > 0 && avgFood > 0 ) {
return numAnimals * avgFood;
}
return -1;
}
const calculateFoodOrder = (n = 0, f = 0) => (Number.isInteger(n) && Number.isInteger(f) && n > 0 && f > 0 ? n * f : -1);
console.log(calculateFoodOrder()); // -1
console.log(calculateFoodOrder(-1,4)); // -1
console.log(calculateFoodOrder(1,3));//3
console.log(calculateFoodOrder([], 200)); // -1
console.log(calculateFoodOrder(Infinity, 200)); // -1
document.querySelectorAll(`[class^=line]`).forEach((item, i) => {
const parent = item.closest(`.value${i + 1}`);
if (i < 7 && parent) {
item.classList.add('visible');
}
})
// ==UserScript==
// @name multiup
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://multiup.org/en/mirror/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
setTimeout(() => {
$('form').on('submit', function(e) {
e.preventDefault();
console.log('click')
window.location.href = $(this).find('button').attr('link');
})
})
})();
<div id="carousel" class="view">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
</div>
const carusel = document.querySelector('#carousel');
carusel.innerHTMl = '';
[...carusel.children]
.sort(() => Math.random() - 0.5)
.forEach(v => carusel.append(v));