This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo: false | |
language: node_js | |
node_js: "12" | |
notifications: | |
email: false | |
git: | |
submodules: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculate(str){ | |
let result = ''; | |
let num = ''; | |
let arrayOfElements = []; | |
if(/[^0-9\.\$\+\-\*]/.test(str)) { | |
return '400: Bad request'; | |
} else { | |
for (let i = 0; i < str.length; i++) { | |
if (str[i] === "$") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Calculator = function () { | |
const operators = { // Задаем набор методов | |
"+": (value1, value2) => { | |
return value1 + value2 | |
}, | |
"-": (value1, value2) => { | |
return value1 - value2 | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Accumulator = function (startingValue) { | |
this.value = startingValue; | |
this.read = function () { | |
this.value += +prompt('Insert new value (task 3)', 0); | |
} | |
}; | |
const accumulator = new Accumulator(1); | |
accumulator.read(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Calculator = function () { | |
this.read = function () { | |
this.value1 = +prompt('Insert first value(task 2)', 0); | |
this.value2 = +prompt('Insert second value(task 2)', 0); | |
// Почему так? Да потому что вводимые параметры имеют тип данных string, а при сложение двух строк/числа и строки начинают происходить удивительные вещи(например, оператор + тупо складывает строки в прямом смысле, не суммируя их) | |
}; | |
this.sum = function () { | |
return this.value1 + this.value2; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Да, могут. Для этого они должны возвращать один и тот же объект | |
const obj = {}; | |
const A = function() { | |
return obj; | |
}; | |
const B = function () { | |
return obj; | |
}; |