-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
99592df
commit 8ebb6b4
Showing
8 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Challenge 26 | ||
|
||
Santa Claus has already delivered all the presents! Now he's reviewing the productivity reports of the elves. But there's a problem: **the Product Owner, Mrs. Claus 🧑🎄✨**, needs to quickly understand if the elves met the estimated times. They are doing **Agile Scream**. | ||
|
||
To help **Mrs. Claus**, your task is to calculate the completed percentage of each task and return it rounded to the nearest whole number. This will allow her to better plan for the next Christmas and keep everyone happy. | ||
|
||
This is the function she's expecting: | ||
|
||
```js | ||
getCompleted('01:00:00', '03:00:00') // Expected result: '33%' | ||
getCompleted('02:00:00', '04:00:00') // Expected result: '50%' | ||
getCompleted('01:00:00', '01:00:00') // Expected result: '100%' | ||
getCompleted('00:10:00', '01:00:00') // Expected result: '17%' | ||
getCompleted('01:10:10', '03:30:30') // Expected result: '33%' | ||
getCompleted('03:30:30', '05:50:50') // Expected result: '60%' | ||
``` | ||
|
||
**🎁 Now Santa Claus and the elves deserve a break. We hope they enjoyed AdventJS and will recommend it to their friends!** | ||
|
||
### Solutions | ||
|
||
- [Python](./solution.py) | ||
- [JavaScript](./solution.js) | ||
- [TypeScript](./solution.ts) | ||
|
||
## Stars earned | ||
|
||
 |
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,17 @@ | ||
/** | ||
* @param {string} timeWorked - Time worked in hh:mm:ss format. | ||
* @param {string} totalTime - Total estimated time in hh:mm:ss format. | ||
* @returns {string} - The completed percentage rounded to the nearest integer with a % sign. | ||
*/ | ||
export default function getCompleted(timeWorked, totalTime) { | ||
/** @type {Date} */ | ||
const worked = new Date(`1970-01-01T${timeWorked}`) | ||
|
||
/** @type {Date} */ | ||
const totalWorked = new Date(`1970-01-01T${totalTime}`) | ||
|
||
/** @type {string} */ | ||
const productivity = `${Math.round((worked.getTime() / totalWorked.getTime()) * 100)}%` | ||
|
||
return productivity | ||
} |
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,10 @@ | ||
from datetime import datetime | ||
|
||
|
||
def get_completed(time_worked: str, total_time: str) -> str: | ||
worked: datetime = datetime.fromisoformat(f"1970-01-01T${time_worked}") | ||
total_worked: datetime = datetime.fromisoformat(f"1970-01-01T${total_time}") | ||
productivity: str = ( | ||
f"${round(number=(worked.timestamp() / total_worked.timestamp()) * 100)}%" | ||
) | ||
return productivity |
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,39 @@ | ||
import fn from './solution' | ||
|
||
describe('Challenge 26: measure elves productivity', () => { | ||
it('Test 01', () => { | ||
const result: `${string}%` = fn('01:00:00', '03:00:00') | ||
const expected: `${string}%` = '33%' | ||
expect(result).toBe(expected) | ||
}) | ||
|
||
it('Test 02', () => { | ||
const result: `${string}%` = fn('02:00:00', '04:00:00') | ||
const expected: `${string}%` = '50%' | ||
expect(result).toBe(expected) | ||
}) | ||
|
||
it('Test 03', () => { | ||
const result: `${string}%` = fn('01:00:00', '01:00:00') | ||
const expected: `${string}%` = '100%' | ||
expect(result).toBe(expected) | ||
}) | ||
|
||
it('Test 04', () => { | ||
const result: `${string}%` = fn('00:10:00', '01:00:00') | ||
const expected: `${string}%` = '17%' | ||
expect(result).toBe(expected) | ||
}) | ||
|
||
it('Test 05', () => { | ||
const result: `${string}%` = fn('01:10:10', '03:30:30') | ||
const expected: `${string}%` = '33%' | ||
expect(result).toBe(expected) | ||
}) | ||
|
||
it('Test 06', () => { | ||
const result: `${string}%` = fn('03:30:30', '05:50:50') | ||
const expected: `${string}%` = '60%' | ||
expect(result).toBe(expected) | ||
}) | ||
}) |
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,6 @@ | ||
export default function getCompleted(timeWorked: string, totalTime: string): `${string}%` { | ||
const worked: Date = new Date(`1970-01-01T${timeWorked}`) | ||
const totalWorked: Date = new Date(`1970-01-01T${totalTime}`) | ||
const productivity: `${string}%` = `${Math.round((worked.getTime() / totalWorked.getTime()) * 100)}%` | ||
return productivity | ||
} |