From ee2605545aa2411bf5a796e28311ac31614359d2 Mon Sep 17 00:00:00 2001 From: TheHomeGera Date: Mon, 18 Oct 2021 14:20:35 +0500 Subject: [PATCH 1/3] tasks all --- topic-5/task-1/index.js | 14 ++++++++++---- topic-5/task-2/index.js | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/topic-5/task-1/index.js b/topic-5/task-1/index.js index c7afee6..de60051 100644 --- a/topic-5/task-1/index.js +++ b/topic-5/task-1/index.js @@ -8,10 +8,16 @@ function breadcrumbCalculate(setter){ - for (let i = 0; i < 1e7; i++) { - i++; - setter(i); - } + let i = 0 + const timer = setInterval(() => { + if( i === 1e7) { + clearInterval(timer); + } + else { + i++; + setter(i); + } + }); } module.exports.breadcrumbCalculate = breadcrumbCalculate; diff --git a/topic-5/task-2/index.js b/topic-5/task-2/index.js index 625dbdc..fe9b5da 100644 --- a/topic-5/task-2/index.js +++ b/topic-5/task-2/index.js @@ -8,12 +8,43 @@ Как строить класс и как экспортиоровать функцию resolveBudget, дело ваше, полная свобода. */ +import { stringOfPurchases } from "./list-items"; + +const Codes = { + 5411: "Продукты", + 5732: "Электроника", + 5812: "Составная еда", + 5993: "Никотиновый глицерин", + 5039: "Строительные материалы", + 5172: "Комплектующие авто", + 5651: "Одежда" +} function resolveBudget(string){ - + if (typeof(string) !== 'string'){ + throw new Error('Не то значение') + } + + const result = stringOfPurchases.split(', ').map(x => { + const array = x.split(' '); + return new Purchase( + array.slice(0, array.length - 2).join(' '), + array[array.length - 2], + array[array.length - 1], + ); + }); + + return result; } class Purchase{ + constructor(value, type, code, name) { + this.code = code; + this.type = Codes[type]; + this.value = value; + this.name = name; + } } -module.exports.resolveBudget = resolveBudget; +const _resolveBudget = resolveBudget; +export { _resolveBudget as resolveBudget }; From a6f4340afac6dc3d76dcc3c809f6265522a29475 Mon Sep 17 00:00:00 2001 From: TheHomeGera Date: Fri, 22 Oct 2021 21:41:45 +0500 Subject: [PATCH 2/3] fix --- topic-5/task-2/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topic-5/task-2/index.js b/topic-5/task-2/index.js index fe9b5da..a263f70 100644 --- a/topic-5/task-2/index.js +++ b/topic-5/task-2/index.js @@ -6,7 +6,7 @@ Класс должен иметь поля: code, type, value, name. type - наименование группы по МСС, а value сумма затраченная на приобритение данного продукта. - Как строить класс и как экспортиоровать функцию resolveBudget, дело ваше, полная свобода. + Как строить класс и как экспортиоровать функцию resolveBudget, дело ваше, полная свобода. */ import { stringOfPurchases } from "./list-items"; From 99c10c82d70d4f1238725793d071ee4db7adfdc1 Mon Sep 17 00:00:00 2001 From: TheHomeGera Date: Fri, 22 Oct 2021 21:43:24 +0500 Subject: [PATCH 3/3] fix --- topic-5/task-2/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/topic-5/task-2/index.js b/topic-5/task-2/index.js index a263f70..ceb4054 100644 --- a/topic-5/task-2/index.js +++ b/topic-5/task-2/index.js @@ -10,7 +10,7 @@ */ import { stringOfPurchases } from "./list-items"; -const Codes = { +const CodesTypes = { 5411: "Продукты", 5732: "Электроника", 5812: "Составная еда", @@ -40,7 +40,7 @@ function resolveBudget(string){ class Purchase{ constructor(value, type, code, name) { this.code = code; - this.type = Codes[type]; + this.type = CodesTypes[type]; this.value = value; this.name = name; }