Каким образом запустить первых два promise , а параллельно выполнить 3й с первыми двумя ?
Promise.all([
promise4000(),
promise2000(),
promise3000(),
]).then(result => {
// do something
});
function foo(props) {
var a = isNumber(props.a) ? props.a : 100;
var b = isNumber(props.b) ? props.b : 200;
var c = isNumber(props.c) ? props.c : 300;
var d = isNumber(props.d) ? props.d : 400;
return a + b + c + d;
}
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
const foo = ({ a = 100, b = 200, c = 300, d = 400 }) => a + b + c + d;
foo({ a: 0, d: 500 }); // 1000
import libraryName from 'libraryName';
libraryName.someMethod();
import { someMethod } from 'libraryName';
someMethod();
function filterEmptyProps(obj) {
const result = {};
Object.entries(obj).forEach(([ key, val ]) => {
if (val || val === 0) {
result[key] = val;
}
});
return result;
}
import React from 'react';
import styled from 'styled-components';
const SVG = styled.svg`
display: inline-block;
vertical-align: middle;
`;
const Icon = ({ name, ...props }) {
if (!name) {
throw new Error('Unknown icon name!');
}
return (
<SVG {...props}>
<use xlinkHref={`#icon-${name}`} />
</SVG>
);
}
export default Icon;
import React from 'react';
import styled from 'styled-components';
import { Icon } from './components';
const StyledIcon = styled(Icon)`
fill: ${props => props.state.fill};
`;
const Example = ({ iconState }) => <StyledSVG name="profile" state={iconState} />;
export default Example;
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
class Example extends Component {
handler = () => {
this.props.history.push('/cources');
};
render() { /* ... */ }
}
export default withRouter(Example);
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
class Example extends Component {
render() {
return <Link to="/cources" />;
}
}
export default Example;
var TIME_FROM = 0;
var TIME_TO = 9;
var date = new Date();
var clientLocalHour = date.getHours();
if (clientLocalHour >= TIME_FROM && clientLocalHour < TIME_TO) {
$('.ageWindow').fadeIn(100);
}
function addAge() {
$('.ageWindow').fadeOut(500);
}
var SERVICE_TIMEZONE = 3;
var TIME_FROM = 0;
var TIME_TO = 9;
var date = new Date();
var clientLocalHour = date.getHours();
var timezoneOffset = date.getTimezoneOffset() / 60;
var serviceComputedHour = clientLocalHour + timezoneOffset + SERVICE_TIMEZONE;
if (serviceComputedHour >= TIME_FROM && serviceComputedHour < TIME_TO) {
$('.ageWindow').fadeIn(100);
}
function addAge() {
$('.ageWindow').fadeOut(500);
}
const foo = (arg: number) => { /* do something with number type */ };
var sorted_fruits_2016 = fruits_2016.sort(sortById);
var sorted_fruits_2017 = fruits_2017.sort(sortById);
var sorted_fruits_2018 = fruits_2018.sort(sortById);
var result_2016_2017 = compare(sorted_fruits_2016, sorted_fruits_2017);
var result_2017_2018 = compare(sorted_fruits_2017, sorted_fruits_2018);
function compare(oldArr, newArr) {
var deleted = [], added = [], notChanged = [];
var innerIndex = 0;
if (!newArr.length) {
return {
added: added,
deleted: oldArr,
notChanged: notChanged
};
}
for (var i = 0; i < newArr.length; i++) {
if (innerIndex >= oldArr.length - 1) {
added.push(newArr[i]);
continue;
}
for (var j = innerIndex; j < oldArr.length; j++) {
var newElId = newArr[i][0];
var oldElId = oldArr[j][0];
if (newElId > oldElId) {
deleted.push(oldArr[j]);
} else if (newElId < oldElId) {
added.push(newArr[i]);
innerIndex = j;
break;
} else {
notChanged.push(newArr[i]);
innerIndex = j + 1;
break;
}
}
}
return {
deleted: deleted,
added: added,
notChanged: notChanged
};
}
function sortById(a, b) {
return a[0] - b[0];
}
var result = compare(fruits_2016, fruits_2017);
console.log('result', result);
function compare(oldArr, newArr) {
var sortedOldArr = oldArr.sort(sortById);
var sortedNewArr = newArr.sort(sortById);
return compareSorted(sortedOldArr, sortedNewArr);
}
function compareSorted(oldArr, newArr) {
var deleted = [], added = [], notChanged = [];
var innerIndex = 0;
if (!newArr.length) {
return {
added: added,
deleted: oldArr,
notChanged: notChanged
};
}
for (var i = 0; i < newArr.length; i++) {
if (innerIndex >= oldArr.length - 1) {
added.push(newArr[i]);
continue;
}
for (var j = innerIndex; j < oldArr.length; j++) {
var newElId = newArr[i][0];
var oldElId = oldArr[j][0];
if (newElId > oldElId) {
deleted.push(oldArr[j]);
} else if (newElId < oldElId) {
added.push(newArr[i]);
innerIndex = j;
break;
} else {
notChanged.push(newArr[i]);
innerIndex = j + 1;
break;
}
}
}
return {
deleted: deleted,
added: added,
notChanged: notChanged
};
}
function sortById(a, b) {
return a[0] - b[0];
}
const loading = () => ({ ... });
const success = () => ({ ... });
const error = (message) => ({ ... });
export const send = ({ name, phone }) => { ... };
export const send = ({ name, phone }) => { ... };
function loading() {
return { ... };
};
function success() {
return { ... };
};
function error(message) {
return { ... };
};
var trouble = +prompt('What is wrong?');
var CABEL = 1;
var ROUTER = 2;
var COMPUTER = 3;
switch (trouble) {
case CABEL:
console.log('check your cabel');
break;
case ROUTER:
console.log('check your router');
break;
case COMPUTER:
console.log('reload your PC');
break;
default:
console.log('uncorrect trouble');
}