n, n + 1, n + 2, ..., n + m - 1
1, 2, 3, 4, 5
0, 1, 2, 3, 4
{ sum: 15, count: 5 }
{ sum: 10, count: 5 }
x = 15 / 5;
x = 10 / 5;
class Example extends Component {
state = {
eventsList,
selectedEvent,
};
handleSelectEvent(event) {
this.setState({ selectedEvent: event });
}
render() {
const { eventsList, selectedEvent } = this.state;
return (
<Wrapper>
{selectedEvent && <EventDetails event={selectedEvent} />}
<ul>
{eventsList.map(event => (
<li
key={event.id}
onClick={() => this.handleSelectEvent(event)}
>
{event.name}
</li>
))}
</ul>
</Wrapper>
);
}
}
<BrowserRouter>
<App />
</BrowserRouter>
<Switch>
<Route exact path="/" component={Home} />
<Route path="/events" component={EventsList} />
<Route path="/event/:id" component={EventDetails} />
</Switch>
class EventsList extends Component {
state = {
eventsList,
};
render() {
const { eventsList } = this.state;
return (
<Wrapper>
<ul>
{eventsList.map(event => (
<li key={event.id}>
<Link to={`/event/${event.id}`}>{event.name}</Link>
</li>
))}
</ul>
</Wrapper>
);
}
}
class EventsList extends Component {
componentDidMount() {
const elementId = this.props.match.params.id;
}
render() {
...
}
}
class Game {
// some stuff
createGame() {
this.players = [];
for (let i = 0; i < this.playersCount; i++) {
const player = new Player({
name: `Player ${i}`,
cards: this.createCards()
});
this.players.push(player);
}
}
createCards() {
// some stuff
}
// some stuff
}
export default (state = initState, action) => {
if(action.type === 'ADD_VAL'){
return [
...state,
action.date
];
}
return state;
};
const values = (state = initState, action) => {
if(action.type === 'ADD_VAL'){
return [
...state,
action.date
];
}
return state;
};
export default values;
const map = {};
srcArray.forEach(({ ID, ...Coords }) => {
map[ID] = map[ID] || { ID, Coords: [] };
map[ID].Coords.push(Coords);
});
const resultArray = Object.values(map);
const map = {};
srcArray.forEach(({ ID, lat, lng }) => {
map[ID] = map[ID] || { ID, Coords: [] };
map[ID].Coords.push({ lat, lng });
});
const resultArray = Object.values(map);
const resultArray =
Object.values(srcArray.reduce((map, { ID, ...Coords }) => {
map[ID] = map[ID] || { ID, Coords: [] };
map[ID].Coords.push(Coords);
return map;
}, {}));
const resultArray =
Object.values(srcArray.reduce((map, { ID, lat, lng }) => {
map[ID] = map[ID] || { ID, Coords: [] };
map[ID].Coords.push({ lat, lng });
return map;
}, {}));
var map = {};
var resultArray = [];
srcArray.forEach(function(el) {
map[e.ID] = map[el.ID] || { ID: el.ID, Coords: [] };
map[el.ID].Coords.push({ lat: el.lat, lng: el.lng });
});
for(var key in map) {
resultArray.push(map[key]);
}
var prevSelection;
document.addEventListener('mouseup', function() {
var selection;
if (window.getSelection) {
selection = window.getSelection().toString();
} else if (document.selection) {
selection = document.selection.createRange().text;
}
if (!selection && prevSelection.length) {
alert('Text uselected');
}
prevSelection = selection;
});
i < this.arr.length
this.httpService.getList().subscribe(data => {
this.arr = [...this.arr, ...data];
});
this.httpService.getList().subscribe(data => {
this.arr = this.arr.concat(data);
});
this.httpService.getList().subscribe(data => {
data.forEach(el => this.arr.push(el));
});
grafik.forEach(elem => {
elem.attr = attr;
});
grafik.forEach(elem => {
elem.attr = attr.map(el => ({ ...el }));
});
grafik.forEach(elem => {
elem.attr = attr.map(el => Object.assign({}, el));
});
list = { value: array[i], rest: list };
{ value: 10: rest: null };
var x = 10;
x = x + 5;
x = 10 + 5;
x = 15;
var obj = { // создаем объект доступный по ссылке obj
prop: 'example prop'
};
obj.self = obj; // добавляем в объект свойство self ссылающееся на сам объект
var summidle = 3;
var sum = 16;
if (summidle === 3 && sum > 11 && sum < 22){
alert("legend");
}
function newExpression(constructor) {
if ( typeof constructor !== 'function') {
throw new TypeError(constructor + 'is not a constructor');
}
var args = Array.prototype.slice.call(arguments, 1);
var obj = Object.create(constructor.prototype);
return constructor.apply(obj, args) || obj;
}
var User = function(name) {
this.name = name;
}
User.prototype.getName = function() {
return this.name;
}
const obj = {};
User = User.bind(obj, "Sarah");
var john = new User('John');
console.log(john.getName()); // 'Sarah'
let foo = {};
let bar = {};
foo.barLink = bar;
bar.fooLink = foo;
foo = bar = null;
class Person {
constructor(name) {
this.name = name;
}
printName() {
console.log(this.name);
}
}
let john = new Person('John');
const obj = {};
obj.printJohnName = john.printName.bind(john);
john = null;
obj.printJohnName(); // 'John'
import React from 'react';
export default Task;
constructor(props) {
super(props);
this.state = {
isOpened: false,
};
this.clickHandler = this.clickHandler.bind(this);
}
clickHandler = e => {
// your stuff
};
this.setState(prevState => ({
isOpened: !prevState.isOpened,
}));
var duration = 32 * 60 * 1000;
var step = 1000;
var endsAfter = duration;
var timer = setTimeout(alert, duration, 'Hello world!');
var interval = setInterval(function() {
endsAfter -= step;
if (endsAfter <= 0) clearInterval(interval);
console.log('Timeout через: ', endsAfter);
}, step);
const initialState: {
entities: {}.
isLoading: {
'ALL': false,
},
isError: {
'ALL': false,
}
}
const someEntityReduser = (state = initalState, action) => {
const { type, payload } = action;
switch (type) {
case GET_ALL_ENTITIES_REQUEST:
return {
...state,
isLoading: {
...state.isLoading,
'ALL': true,
},
isError: {
...state.isError,
'ALL': false,
},
};
case GET_ALL_ENTITIES_SUCCESS:
return {
...state,
entities: payload, // либо нормализация если приходят массивом
isLoading: {
...state.isLoading,
'ALL': false,
},
};
case UPDATE_ENTITY_REQUEST:
return {
...state,
isLoading: {
...state.isLoading,
[payload.id]: true,
},
isError: {
...state.isError,
[payload.id]: false,
},
};
case UPDATE_ENTITY_SUCCESS:
return {
...state,
entities: {
...state.entities,
[payload.id]: payload,
},
isLoading: {
...state.isLoading,
[payload.id]: false,
},
};
/* other cases */
}
}
function SetUserManager(config) {
this.client = new ClientUser();
this.clientManager = new ClientManager({
user: this.client
});
this.options = {
name: config.name,
key: config.key
};
this.cookies = [];
client.login(options);
this.viewer();
}
SetUserMagager.prototype.viewer = function() {
this.client.on('login', () => {
this.client.setLogin();
});
this.client.on('msg', (session) => {
serveSession(session);
});
this.clientManager.on('user', (data) => {
serveNewUser(data);
});
}
class SetUserMagager {
constructor(config) {
this.client = new ClientUser();
this.clientManager = new ClientManager({
user: this.client
});
this.options = {
name: config.name,
key: config.key
};
this.cookies = [];
client.login(options);
this.viewer();
}
viewer() {
this.client.on('login', () => {
this.client.setLogin();
});
this.client.on('msg', (session) => {
serveSession(session);
});
this.clientManager.on('user', (data) => {
serveNewUser(data);
});
}
}
module.exports.person = async () => await sqlQuery();
module.exports.person = async () => [await sqlQuery1(), await sqlQuery2()];
module.exports.person = async id => {
const user = await getUser(id);
const permissions = await getPermissions(user.role);
return {
user,
permissions,
};
}
module.exports.person = args => sqlQuery(args);
const user = async person(id);