Skip to content

Instantly share code, notes, and snippets.

View NikitaGlukhi's full-sized avatar

Nikita Glukhi NikitaGlukhi

  • Valor-Software
  • Kharkiv
View GitHub Profile
@NikitaGlukhi
NikitaGlukhi / .travis.yml
Last active January 5, 2021 10:13
Travis CI config and bash script for deploying to Firebase preview channels and commenting GitHub PRs
sudo: false
language: node_js
node_js: "12"
notifications:
email: false
git:
submodules: false
@NikitaGlukhi
NikitaGlukhi / gist:01383bf4acb01c55946a6d72059dc787
Created December 12, 2018 17:35
Route calculator. Final solution
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] === "$") {
@NikitaGlukhi
NikitaGlukhi / gist:51cb63bc3cf7afc7557d4e155baf34a9
Created December 10, 2018 12:59
Task 4 for cunstructor functions
const Calculator = function () {
const operators = { // Задаем набор методов
"+": (value1, value2) => {
return value1 + value2
},
"-": (value1, value2) => {
return value1 - value2
}
};
@NikitaGlukhi
NikitaGlukhi / gist:098788d2fb5fc99f7324757969097d81
Created December 10, 2018 12:57
Task 3 for constructor function
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();
@NikitaGlukhi
NikitaGlukhi / gist:11765a367590fb6f1f58f2c1e4e452bf
Created December 10, 2018 12:55
Task 2 for constructor functions
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;
};
@NikitaGlukhi
NikitaGlukhi / gist:a804e847cc6c76e981832085476842b9
Created December 10, 2018 12:53
Tasks 1 for cunstructor functions
// Да, могут. Для этого они должны возвращать один и тот же объект
const obj = {};
const A = function() {
return obj;
};
const B = function () {
return obj;
};