-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
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
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"`. |
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
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"); | ||
}); | ||
}); |
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
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(",", "")}`; | ||
} |
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