var stateMonitor = new ymaps.Monitor(myPolygon.editor.state);
stateMonitor.add("drawing", function (newValue) {
myPolygon.options.set("strokeColor", newValue ? '#FF0000' : '#0000FF');
});
var X = 52;
console.time('someFunction1');
for (var i=0,x=0; i < 10000; i++) {
if ([52, 62, 72, 82, 92].indexOf(X) !== -1) {
x++;
}
}
console.log(x);
console.timeEnd('someFunction1');
console.log('--------------');
console.time('someFunction2');
for (var i=0,y=0; i < 10000; i++) {
switch (X) {
case 52:
case 62:
case 72:
case 82:
case 92:
y++;
break;
}
}
console.log(y);
console.timeEnd('someFunction2');
console.log('--------------');
console.time('someFunction3');
for (var i=0,z=0; i < 10000; i++) {
if({52:1, 62:1, 72:1, 82:1, 92:1}[X]) { z++; }
}
console.log(z);
console.timeEnd('someFunction3');
10000
someFunction1: 2.541ms
--------------
10000
someFunction2: 1.192ms
--------------
10000
someFunction3: 3.676ms
function groupByType(array) {
return (array.length < 2) ? [array] : array.reduce(function(acc, current) {
if(typeof current != acc.last){
acc.last=typeof current;
acc.result.push([]);
acc.i++;
}
acc.result[acc.i].push(current);
return acc;
}, { result: [], i: -1,last:false }).result;
};
function groupByType(array) {
return (array.length < 2) ? [array] : array.reduce(function(acc, current) {
if(typeof current != acc.last){
acc.last=typeof current;
acc.result.push([]);
}
acc.result[acc.result.length-1].push(current);
return acc;
}, { result: [] ,last:false }).result;
};
groupByType([1, 2, 3, 'a', 4, 5, 'b', 9, 'n', 'm']);
$(document).on('keydown',function (event) {
if (event.ctrlKey&&event.key=='*') {
// кодэ
}
})
<?php
$optionsArray = array();
if (is_array($organizationList)&&!empty($organizationList))
{
foreach ($organizationList as $org)
{
$optionsArray[]='<option value="'.$org['idn'].'">'.$org['name'].'</option>';
}
}
?><!DOCTYPE html>
<html>
..............
<select name="organization_id" id="getOrg">
<option disabled selected>Укажите организацию...</option>
<?=implode("",$optionsArray)?>
</select>
var data = [{
idn: 3,
name: 'first'
}, {
idn: 4,
name: 'second'
}, {
idn: 5,
name: 'third'
}];
var $select = $('<select/>', {
class: 'form-control',
html: $.map(data, function(org) {
return $('<option/>', {
value: org.idn,
text: org.name
})
})
}).on('change', function() {
console.log($(this).val());
}).trigger('change');
$('.container').append($select)
<ul id="menu-topen-1" class="menu">
<li class="menu-item"><a href="#solutions">Solutions</a></li>
<li class="menu-item"><a href="#team">Team</a></li>
<li class="menu-item"><a href="#blog">Blog</a></li>
<li class="menu-item"><a href="#contact">Contact</a></li>
</ul>
<ul id="menu-topen-1" class="menu">
<li class="menu-item"><a href="/#solutions">Solutions</a></li>
<li class="menu-item"><a href="/#team">Team</a></li>
<li class="menu-item"><a href="/#blog">Blog</a></li>
<li class="menu-item"><a href="/#contact">Contact</a></li>
</ul>
var toSendData = $.extend({},myObj,flavor);
var TheConstructor = function(params) {
var
happinessCap = 100,
desireCap = 100,
ageFactor = (function(age) {
return 33 / age;
})(params.age),
maxAge=45,
minAge=18,
woman = {
_age: params.age,
_happiness: 42,
_desire: 0,
bitchCoeff: params.bitchCoeff
};
woman.dance = function() {
woman._happiness += woman._age / woman.bitchCoeff;
if (woman._happiness >= happinessCap) {
woman._happiness = happinessCap;
}
}
woman.drinkAlcohol = function() {
if(woman._age<minAge){
throw new AgeRestriction(woman._age);
}
if(woman._age>maxAge){
return;
}
woman._desire += woman._age * ageFactor / woman.bitchCoeff;
if (woman._desire >= desireCap) {
woman._desire = desireCap;
}
}
woman.isAccessible = function() {
return (woman._happiness == happinessCap && woman._desire == desireCap);
}
return {
dance: woman.dance,
drink: woman.drinkAlcohol,
isAccessible: woman.isAccessible,
own:function(){
return (woman.bitchCoeff<1)?woman:{};
}
}
}
function seduce(woman){
var maxAttempts = 5;
for(var i = 1;i<=maxAttempts;i++){
woman.drink();
woman.dance();
if(woman.isAccessible()){
console.log(woman.name + " has been seducted after "+i+" attempts!");
console.info(woman.own());
return true;
}
}
console.error(woman.name + " is a frigid bitch!");
return false;
}
var cheerLeader = new TheConstructor({age:20,bitchCoeff:0.25})
cheerLeader.name = "Masha";
seduce(cheerLeader);
var businessWoman = new TheConstructor({age:33,bitchCoeff:2.5})
businessWoman.name="Olga Victorovna";
seduce(businessWoman);
var schoolTeacher = new TheConstructor({age:27,bitchCoeff:1.1})
schoolTeacher.name="Valentina";
seduce(schoolTeacher);
this.BuildWidget = function(widgetParams){ var widget={params:widgetParams}; ... ; return widget; }.
<div ang="10"></div>
div{
transform:rotate(attr(ang, deg));
}
var angle=12.5;
$(marker._icon).css({
transform:"rotate("+angle+"deg)"
})
var coords = {
'showMap_1':{
[55.66837606904998,37.484163499999944]
},
'showMap_2':{
[55.66266356906509,37.478000999999914]
},
...
}
$('tr[id=^showMap]').click(function() {
myMap.setZoom( 15 );
myMap.panTo(coords[$(this).attr('id')],{flying:1});
TweenMax.to(window, 0.5, {scrollTo:{y: document.getElementById("map").offsetTop-10}})
});
oninput = function() {
(function() {
var a = Number(document.getElementById("itemPrice").value);
var b = Number(document.getElementById("EMC").value);
var c = Number(document.getElementById("amount").value);
var d = Number(document.getElementById("koef").value);
var v = (c * a + b) * 0.1 + c * a + b;
var f = v * d
var x = (f * 0.02 + f) + ((f * 0.02 + f) * 0.22)
if (x >= 0 && v <= 10000) {
document.getElementById("result").innerHTML = x.toFixed(2);
}
}()),
(function() {
var W = Number(document.getElementById("itemweight").value);
var Wresult = W * 14;
if (Wresult >= 0 && Wresult <= 10000) {
document.getElementById("resultWeight").innerHTML = Wresult.toFixed(2);
}
}())
}
<a href="#modal" id="fancybox">Показать слайдер в окне</a>
<div class="modal" id="modal">
<div class="slider">
<div id="slick">
<div class="slider__item">
<div>1</div>
</div>
<div class="slider__item">
<div>2</div>
</div>
<div class="slider__item">
<div>3</div>
</div>
<div class="slider__item">
<div>4</div>
</div>
<div class="slider__item">
<div>5</div>
</div>
<div class="slider__item">
<div>6</div>
</div>
<div class="slider__item">
<div>7</div>
</div>
</div>
</div>
<div class="slider">
<div id="slick2">
<div class="slider__item">
<div>11</div>
</div>
<div class="slider__item">
<div>22</div>
</div>
<div class="slider__item">
<div>33</div>
</div>
<div class="slider__item">
<div>44</div>
</div>
<div class="slider__item">
<div>55</div>
</div>
<div class="slider__item">
<div>66</div>
</div>
<div class="slider__item">
<div>77</div>
</div>
</div>
</div>
</div>
$(document).ready(function() {
$('#fancybox').fancybox({
autoSize: true,
afterShow: function() {
var main = '#slick';
var support = '#slick2';
$(main).slick({
slidesToShow: 1,
slidesToScroll: 1,
arrows: false,
fade: true,
asNavFor: support,
dots: false,
responsive: true
});
$(support).slick({
slidesToShow: 3,
slidesToScroll: 1,
asNavFor: main,
dots: true,
centerMode: true,
variableWidth: true,
focusOnSelect: true
});
}
});
})