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
<?php
class A
{
public function a()
{
echo "a";
}
}
class B extends A
{
public function controll($method)
{
if (method_exists($this, $method)) { // проверяем существует ли метод
$reflectionMethod = new ReflectionMethod($this, $method);
if ($reflectionMethod->isPublic()) { // проверка является ли метод публичным
return $this->$method(); // вызываем функцию
}
}
}
}
$b = new B;
$b->controll("a");
document.querySelectorAll(`[class^=line]`).forEach((item, i) => {
const parent = item.closest(`.value${i + 1}`);
if (i < 7 && parent) {
item.classList.add('visible');
}
})
$url = \yii\helpers\Url::toRoute(['delete-select']);
$script = <<< JS
$("#delete-select").on("click", function(e){
e.preventDefault()
var keys = $("#w0").yiiGridView("getSelectedRows");
$.ajax({
url: "$url",
type: "POST",
data: {id: keys},
success: function(){
alert("yes")
},
error : function(){
alert("Ошибка при отправке данных: перезагрузите страницу!");
}
})
});
JS;
$this->registerJs($script, yii\web\View::POS_READY);