Created
July 14, 2022 19:06
-
-
Save evgeniyworkbel/6d96712994d25b18c234c87a0097011f to your computer and use it in GitHub Desktop.
Курс "JS: Объектно-ориентированный дизайн" (Хекслет)
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
/ |
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
/ |
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
dates.js | |
Реализуйте и экспортируйте по умолчанию функцию, которая переводит входные данные в удобный для построения графика формат. | |
На вход эта функция принимает три аргумента: массив данных; дата начала периода; дата конца периода. Данные представлены в формате объекта вида { value: 14, date: '02.08.2018' }, а даты диапазона в формате 'yyyy-MM-dd'. | |
Диапазон дат задаёт размер выходного массива, который должна сгенерить реализуемая функция. Правила формирования итогового массива: | |
он заполняется записями по всем дням из диапазона begin - end. | |
если во входном массиве нет данных для какого-то дня из диапазона, то в свойство value записи этого дня установить значение 0. | |
import buildRange from './dates.js'; | |
const dates = [ | |
{ value: 14, date: '02.08.2018' }, | |
{ value: 43, date: '03.08.2018' }, | |
]; | |
const beginDate = '2018-08-01'; | |
const endDate = '2018-08-04'; | |
buildRange(dates, beginDate, endDate); | |
// [ | |
// { value: 0, date: '01.08.2018' }, | |
// { value: 14, date: '02.08.2018' }, | |
// { value: 43, date: '03.08.2018' }, | |
// { value: 0, date: '04.08.2018' }, | |
// ] | |
Подсказки | |
Документация по функциям для работы с датами: | |
https://date-fns.org/v2.16.1/docs/eachDayOfInterval | |
https://date-fns.org/v2.16.1/docs/format |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment