Skip to content

Commit

Permalink
Formatting decimal places #0
Browse files Browse the repository at this point in the history
  • Loading branch information
PheRum committed May 18, 2024
1 parent 4d765b0 commit 19a5636
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
16 changes: 16 additions & 0 deletions 8_kyu/Formatting decimal places #0/README.md
Original file line number Diff line number Diff line change
@@ -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"`.
9 changes: 9 additions & 0 deletions 8_kyu/Formatting decimal places #0/index.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
5 changes: 5 additions & 0 deletions 8_kyu/Formatting decimal places #0/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function shortenToDate(longDate: string): string {
const [day, mounth, number] = longDate.split(" ");

return `${day} ${mounth} ${number.replace(",", "")}`;
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 19a5636

Please sign in to comment.