let a = prompt("Enter a value", 10); // a, b, c дальше не меняются
let b = prompt("Enter b value", 10); // поэтому можно
let c = prompt("Enter c value", 10); // const
let result;
let discr = (b * b ) - 4 * a * c;
let sqrtDiscr = Math.sqrt(discr); // при отрицат. discr здесь NaN
if(a === 0 && b === 0 && c === 0) { // проверяем уже после вычислений
throw new Error("The values must be bigger than 0");
} else if(discr < 0 ){ // проверяем уже после вычисления sqrtDiscr
throw new Error("This Equation have not solution");
} else if(discr === 0 ){
console.log("This Equation have only 1 solution")
result = (-b) / (2 * a);
} else if (discr > 0){
console.log("This Equation have 2 solution");
result = (- b + sqrtDiscr) / (2 * a) + "; " + (- b - sqrtDiscr) / (2 * a);
}
console.log(result);
a === 0
: у вас будет деление на ноль. function permut8(arr, prepend) {
var i, version, el, result = [];
prepend = prepend || [];
if(arr.length === 1) return [arr];
for( i=0; i<arr.length; i++) {
if( arr.length === 2) {
result.push( prepend.concat( [arr[i], arr[(i+1)%2]] ));
} else {
version = arr.slice();
el = version.splice(i,1);
result = result.concat( permut8( version, prepend.concat(el)));
}
}
return result;
}
var test = permut8( 'abcd'.split('') );
test.map( e=>e.join(' ')).join("\n")
/*
a b c d
a b d c
a c b d
a c d b
a d b c
a d c b
b a c d
b a d c
b c a d
b c d a
b d a c
b d c a
c a b d
c a d b
c b a d
c b d a
c d a b
c d b a
d a b c
d a c b
d b a c
d b c a
d c a b
d c b a
*/
["a", "a"]
получим два одинаковых [["a", "a"], ["a", "a"]]
function nextLexInPlace(arr){
var i, a = -1, b = -1;
for( i = 0; i < arr.length-1; i++) if(arr[i] < arr[1+i]) a = i;
if( !~a) return; // no more permutations
for( i = a + 1; i < arr.length; i++) if(arr[a] < arr[i]) b = i;
swap(arr, a, b);
a++;
b = arr.length - 1;
while( a < b) swap(arr, a++, b--);
return true;
}
function swap( arr, a, b) {
var xx = arr[a];
arr[a] = arr[b];
arr[b] = xx;
}
function allMutations( source) {
var result = [], arr = source.slice();
result.push( arr.sort().slice());
while( nextLexInPlace(arr)) result.push(arr.slice());
return result;
}
var test = ['a','c','c']; JSON.stringify( allMutations(test))
// [["a","c","c"],["c","a","c"],["c","c","a"]]
function* permutator(arr) {
var i, a, b;
function swap( arr, a, b) {
var xx = arr[a];
arr[a] = arr[b];
arr[b] = xx;
}
yield arr.slice();
while(true) {
a = -1, b = -1;
for( i = 0; i < arr.length-1; i++) if(arr[i] < arr[1+i]) a = i;
if( !~a) return;
for( i = a + 1; i < arr.length; i++) if(arr[a] < arr[i]) b = i;
swap(arr, a++, b);
b = arr.length - 1;
while( a < b) swap(arr, a++, b--);
yield arr.slice();
}
}
function allMutations( source) {
var all = [], result, G = permutator(source.slice().sort());
while(true) {
result = G.next();
if(result.done) break;
all.push( result.value);
}
return all;
}
var test = ['a','c','c']; JSON.stringify( allMutations(test))
// [["a","c","c"],["c","a","c"],["c","c","a"]]
transform: rotate( 123rad);
transition: transform 0.08
для плавности, но появляется проблема перескок при пересечении нуля. Когда угол вдруг меняется с минус-Пи на плюс-Пи, phantomjs github.js
function makeStar(side) {
var arr = new Array(side), x, y, mid = (side-1)/2;
for( y = 0; y < side; y++) {
row = arr[y] = new Array(side);
for( x = 0; x < side; x++) {
row[x] = (y===x || x===side-1-y || x===mid || y===mid) ? 1 : 0;
}
}
return arr;
}
makeStar(4)
.reduce((p,c)=>{ return p + c.join(',') + "\n"},'')
/*
1,0,0,1
0,1,1,0
0,1,1,0
1,0,0,1
*/
var kof1 = <?php the_field('kof21'); ?>
, kof2 = <?php the_field('kof22'); ?>
, sum1 = <?php the_field('sum2'); ?>
, total_Sum
;
total_Sum = kof1 * kof2 * sum1
document.body.appendChild( document.createTextNode( total_Sum.toFixed(2) );
var i
, w
, div
, box
, label
, parent = document.body // к чему приклеивать блоки
, perBlock = 5 // сколько в одном блоке
;
for( i = 0; i < widgetSettings.length; i++) {
w = widgetSettings[i];
box = document.createElement('input');
box.type = 'checkbox';
box.id = box.name = w.id;
box.value = w.value;
label = document.createElement('label');
label.appendChild(box);
label.appendChild( document.createTextNode(w.text));
if( i % perBlock === 0) {
if(div) parent.appendChild(div);
div = document.createElement('div');
}
div.appendChild(label);
}
if( (i-1) % perBlock) parent.appendChild(div);
var D = new Date("2017-08-27")
, Till = new Date()
, result = []
;
function pad(s){ return ('00' + s).slice(-2)}
while( D.getTime() < Till.getTime()) {
result.push( '' + D.getFullYear() +'-'+ pad(D.getMonth()+1) +'-'+ pad(D.getDate()));
D.setDate( D.getDate()+1);
}
// 2017-08-27,2017-08-28,2017-08-29,2017-08-30,2017-08-31
function findDevice(id) {
for( let i in devices) {
if( devices.hasOwnProperty(i) && devices[i].id === id)
return devices[i];
}
}
function addDevices(p) {
p.devices = [];
for( let i = 0; i < p.devices_ids.length; i++)
p.devices.push( findDevice( p.devices_ids[i]));
return p;
}
var result = people.map(addDevices);
var $in = $('#input')
, $check = $('#check')
, $links = $('#links')
;
$check.on('click', function () {
var val = $in.val();
$in.val('');
$links.append(
"<a class='link' href='#'>%VALUE%</a>"
.replace('%VALUE%', val)
);
});
var els = {
input: document.getElementById('input'),
check: document.getElementById('check'),
links: document.getElementById('links'),
link: document.createElement('a')
};
els.link.className = 'link';
els.link.href = '#';
els.check.addEventListener('click', function(){
var a = els.link.cloneNode();
a.innerText = els.input.value;
els.input.value = '';
els.links.appendChild(a);
});
document
.getElementById('e-example')
.addEventListener('click', function(){
document.getElementById('search').value = this.innerText;
});
[]
а объекты {}
._.extend = createAssigner(_.allKeys);
var createAssigner = function(keysFunc, undefinedOnly) {
return function(obj) {
var length = arguments.length;
if (length < 2 || obj == null) return obj;
for (var index = 1; index < length; index++) {
var source = arguments[index],
keys = keysFunc(source),
l = keys.length;
for (var i = 0; i < l; i++) {
var key = keys[i];
if (!undefinedOnly || obj[key] === void 0) obj[key] = source[key];
}
}
return obj;
};
};
_.allKeys = function(obj) {
if (!_.isObject(obj)) return [];
var keys = [];
for (var key in obj) keys.push(key);
if (hasEnumBug) collectNonEnumProps(obj, keys);
return keys;
};
jQuery.extend = jQuery.fn.extend = function() {
var options, name, src, copy, copyIsArray, clone,
target = arguments[ 0 ] || {},
i = 1,
length = arguments.length,
deep = false;
// Handle a deep copy situation
if ( typeof target === "boolean" ) {
deep = target;
// Skip the boolean and the target
target = arguments[ i ] || {};
i++;
}
// Handle case when target is a string or something (possible in deep copy)
if ( typeof target !== "object" && !jQuery.isFunction( target ) ) {
target = {};
}
// Extend jQuery itself if only one argument is passed
if ( i === length ) {
target = this;
i--;
}
for ( ; i < length; i++ ) {
// Only deal with non-null/undefined values
if ( ( options = arguments[ i ] ) != null ) {
// Extend the base object
for ( name in options ) {
src = target[ name ];
copy = options[ name ];
// Prevent never-ending loop
if ( target === copy ) {
continue;
}
// Recurse if we're merging plain objects or arrays
if ( deep && copy && ( jQuery.isPlainObject( copy ) ||
( copyIsArray = Array.isArray( copy ) ) ) ) {
if ( copyIsArray ) {
copyIsArray = false;
clone = src && Array.isArray( src ) ? src : [];
} else {
clone = src && jQuery.isPlainObject( src ) ? src : {};
}
// Never move original objects, clone them
target[ name ] = jQuery.extend( deep, clone, copy );
// Don't bring in undefined values
} else if ( copy !== undefined ) {
target[ name ] = copy;
}
}
}
}
// Return the modified object
return target;
};