Skip to content

Commit

Permalink
Upload solution of challenge 26
Browse files Browse the repository at this point in the history
  • Loading branch information
hozlucas28 committed Dec 26, 2024
1 parent 99592df commit 8ebb6b4
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 2 deletions.
Binary file added .github/26-challenge-stars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
| 23 | Find missing numbers | 🟢 | **5** | [Show](./src/23-challenge) |
| 24 | Check if the trees are synchronized | 🟠 | **5** | [Show](./src/24-challenge) |
| 25 | Return the value of the program after executing instructions sequence | 🟠 | **5** | [Show](./src/25-challenge) |
| **Total** | | **/** | **125** | **/** |
| 26 | Measure elves productivity | 🟢 | **5** | [Show](./src/26-challenge) |
| **Total** | | **/** | **130** | **/** |

<h2>
Related
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"test:challenge22": "jest --testPathPattern='/src/22-challenge/.*\\.spec\\.ts$'",
"test:challenge23": "jest --testPathPattern='/src/23-challenge/.*\\.spec\\.ts$'",
"test:challenge24": "jest --testPathPattern='/src/24-challenge/.*\\.spec\\.ts$'",
"test:challenge25": "jest --testPathPattern='/src/25-challenge/.*\\.spec\\.ts$'"
"test:challenge25": "jest --testPathPattern='/src/25-challenge/.*\\.spec\\.ts$'",
"test:challenge26": "jest --testPathPattern='/src/26-challenge/.*\\.spec\\.ts$'"
}
}
28 changes: 28 additions & 0 deletions src/26-challenge/README.md
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

![5 stars](../../.github/26-challenge-stars.png)
17 changes: 17 additions & 0 deletions src/26-challenge/solution.js
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
}
10 changes: 10 additions & 0 deletions src/26-challenge/solution.py
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
39 changes: 39 additions & 0 deletions src/26-challenge/solution.spec.ts
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)
})
})
6 changes: 6 additions & 0 deletions src/26-challenge/solution.ts
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
}

0 comments on commit 8ebb6b4

Please sign in to comment.