-
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.
Grasshopper - Terminal game combat function
- Loading branch information
Showing
4 changed files
with
21 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,5 @@ | ||
## Grasshopper - Terminal game combat function | ||
|
||
https://www.codewars.com/kata/586c1cf4b98de0399300001d | ||
|
||
Create a combat function that takes the player's current health and the amount of damage recieved, and returns the player's new health. Health can't be less than **0**. |
9 changes: 9 additions & 0 deletions
9
8_kyu/Grasshopper - Terminal game combat function/index.test.ts
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 { combat } from "./index"; | ||
|
||
describe("Tests", () => { | ||
it("combat", () => { | ||
expect(combat(100, 5)).toBe(95); | ||
expect(combat(92, 8)).toBe(84); | ||
expect(combat(20, 30)).toBe(0); | ||
}); | ||
}); |
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 combat(health: number, damage: number): number { | ||
const result = health - damage; | ||
|
||
return result > 0 ? result : 0; | ||
} |
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