Skip to content

Instantly share code, notes, and snippets.

View denchistyakov's full-sized avatar

Denis Chistyakov denchistyakov

View GitHub Profile
function defendable(_attacker, _defender) {
const attacker = new Attacker(_attacker);
const defender = new Defender(_defender);
defender.calcMorale(attacker);
return attacker.getSummaryPower() < defender.getSummaryPower();
}
class Player {
constructor(units) {
Object.assign(this, units);
function hasOwnProperty(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
}
function bestPlaces(cityMap) {
const maxX = cityMap[0].length;
const maxY = cityMap.length;
let maxGarbagesCount = 0;
const coordsOfGarbages = cityMap.reduce((acc, line, y) => {
const START_STATE = 0;
const BIG_LETTER = 1;
const SMALL_LETTER = 2;
const NUMBER = 4;
const OPENING_BRACKET = 8;
const CLOSING_BRACKET = 16;
const STATES = {
[START_STATE]: [BIG_LETTER, OPENING_BRACKET],
[BIG_LETTER]: [BIG_LETTER, SMALL_LETTER, NUMBER, OPENING_BRACKET, CLOSING_BRACKET],
const START_STATE = 0;
const BIG_LETTER = 1;
const SMALL_LETTER = 2;
const NUMBER = 4;
const OPENING_BRACKET = 8;
const CLOSING_BRACKET = 16;
const STATES = {
[START_STATE]: [BIG_LETTER, OPENING_BRACKET],
[BIG_LETTER]: [BIG_LETTER, SMALL_LETTER, NUMBER, OPENING_BRACKET, CLOSING_BRACKET],
function parseMolecule(formula) {
// do your science here
let result = [];
while ((formula = parseNextChar(formula)) != '');
function parseNextChar(str) {
const elem = /^[A-Z]{1}[a-z]?/;
const open = /^[({[]/;
const close = /^[)}\]]/;
const digit = /^[0-9]+/;
let match;
/** COMMENT
var water = 'H2O';
parseMolecule(water); // return {H: 2, O: 1}
var magnesiumHydroxide = 'Mg2(OH)2';
parseMolecule(magnesiumHydroxide); // return {Mg: 1, O: 2, H: 2}
var fremySalt = 'K4[ON(SO3)2]2';
parseMolecule(fremySalt); // return {K: 4, O: 14, N: 2, S: 4}
*/ // eslint-valid-jsdoc
function sum(a, b, c) {
return a + b + c;
}
const curriedSum = curry(sum);
console.log(curriedSum(1, 2, 3)); // 6
console.log(curriedSum(1, 2)(3)); // 6
console.log(curriedSum(1)(2)(3)); // 6
console.log(curriedSum(1)(2, 3)); // 6
/**
* Разбор логов
*
* В функцию передаётся текст, содержащий строки вида
*
* 127.0.0.1 [18/Jun/2018:19:53:13 +0000] "POST /api/external/v1/ HTTP/1.1" 200
*
* Функция должна отдавать список объектов вида
*
// Купюры - 50 руб, 100 руб, 500 руб, 1000 руб, 5000 руб.
// Есть ограничение на количество каждой из купюр, его нужно держать в актуальном состоянии
// 1250 -> '1x1000 2x100 1x50'
// 6512 -> 'Введена неверная сумма'
/**
* [{ nom: 1000, count: 10 }]
* { 1000: 10 }
* new Map([[1000, 10], [5000, 5]])
/**
* @param {Number} hours
* @param {Number} minutes
* @param {Number} interval
* @returns {String}
*/
module.exports = (hours, minutes, interval) => {
const hoursInMinutes = hours * 60;
const summaryMinutes = hoursInMinutes + minutes;
const summaryMinutesWithInterval = summaryMinutes + interval;