From 19a5636ccdcfe4aa9925a193dc11d9a566fffe88 Mon Sep 17 00:00:00 2001 From: Valery Malyshev Date: Sat, 18 May 2024 22:23:51 +0300 Subject: [PATCH] Formatting decimal places #0 --- 8_kyu/Formatting decimal places #0/README.md | 16 ++++++++++++++++ 8_kyu/Formatting decimal places #0/index.test.ts | 9 +++++++++ 8_kyu/Formatting decimal places #0/index.ts | 5 +++++ README.md | 4 ++-- 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 8_kyu/Formatting decimal places #0/README.md create mode 100644 8_kyu/Formatting decimal places #0/index.test.ts create mode 100644 8_kyu/Formatting decimal places #0/index.ts diff --git a/8_kyu/Formatting decimal places #0/README.md b/8_kyu/Formatting decimal places #0/README.md new file mode 100644 index 0000000..597c003 --- /dev/null +++ b/8_kyu/Formatting decimal places #0/README.md @@ -0,0 +1,16 @@ +## Formatting decimal places #0 + +https://www.codewars.com/kata/56b0ff16d4aa33e5bb00008e + +**Task Description** +You're re-designing a blog, and the blog's posts have the Weekday Month Day, time format for showing the date and time when a post was made, e.g., `Friday May 2, 7pm`. + +You're running out of screen real estate, and on some pages you want to display a shorter format, `Weekday Month Day` that omits the time. + +Write a function that takes the website date/time in its original string format and returns the shortened format. + +**Input** +Input will always be a string, e.g., `"Friday May 2, 7pm"`. + +**Output** +Output will be the shortened string, e.g., `"Friday May 2"`. diff --git a/8_kyu/Formatting decimal places #0/index.test.ts b/8_kyu/Formatting decimal places #0/index.test.ts new file mode 100644 index 0000000..de3e4cb --- /dev/null +++ b/8_kyu/Formatting decimal places #0/index.test.ts @@ -0,0 +1,9 @@ +import { shortenToDate } from "./index"; + +describe("Tests", () => { + it("shortenToDate", () => { + expect(shortenToDate("Friday May 2, 9am")).toBe("Friday May 2"); + expect(shortenToDate("Tuesday January 29, 10pm")).toBe("Tuesday January 29"); + expect(shortenToDate("Monday December 25, 10pm")).toBe("Monday December 25"); + }); +}); diff --git a/8_kyu/Formatting decimal places #0/index.ts b/8_kyu/Formatting decimal places #0/index.ts new file mode 100644 index 0000000..ad5b953 --- /dev/null +++ b/8_kyu/Formatting decimal places #0/index.ts @@ -0,0 +1,5 @@ +export function shortenToDate(longDate: string): string { + const [day, mounth, number] = longDate.split(" "); + + return `${day} ${mounth} ${number.replace(",", "")}`; +} diff --git a/README.md b/README.md index b0debda..5df5a04 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ ### Katas solved -`Total`: 27 \ -`8_kyu`: 26 \ +`Total`: 28 \ +`8_kyu`: 27 \ `7_kyu`: 0 \ `6_kyu`: 1 \ `5_kyu`: 0 \