Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 'Color Ghost' #169

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions kata/8 kyu/color-ghost/__mocks__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable class-methods-use-this */

class Ghost {
get color(): string {
return 'white';
}
}

export default Ghost;
13 changes: 13 additions & 0 deletions kata/8 kyu/color-ghost/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Ghost from '.';

jest.mock('.');

describe('ghost', () => {
it('should', () => {
expect.assertions(1);

const ghost = new Ghost();

expect(ghost.color).toBe('white');
});
});
17 changes: 17 additions & 0 deletions kata/8 kyu/color-ghost/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function randomInteger(max: number, min = 0): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

class Ghost {
colors: string[];

constructor() {
this.colors = ['white', 'yellow', 'purple', 'red'];
}

get color(): string {
return this.colors[randomInteger(this.colors.length) + 1];
}
}

export default Ghost;
47 changes: 47 additions & 0 deletions kata/8 kyu/color-ghost/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# [Color Ghost](https://www.codewars.com/kata/53f1015fa9fe02cbda00111a)

### Color Ghost

Create a class Ghost

Ghost objects are instantiated without any arguments.

Ghost objects are given a random color attribute of white" or "yellow" or "purple" or "red" when instantiated

```javascript
ghost = new Ghost();
ghost.color; //=> "white" or "yellow" or "purple" or "red"
```

```coffeescript
ghost = new Ghost()
ghost.color #=> "white" or "yellow" or "purple" or "red"
```

```ruby
ghost = Ghost.new
ghost.color #=> "white" or "yellow" or "purple" or "red"
```

```python
ghost = Ghost()
ghost.color #=> "white" or "yellow" or "purple" or "red"
```

```java
Ghost ghost = new Ghost();
ghost.getColor(); //=> "white" or "yellow" or "purple" or "red"
```

```c#
Ghost ghost = new Gost();
ghost.GetColor(); // => "white" or "yellow" or "purple" or "red"
```

---

## Tags

- Fundamentals
- Object-oriented Programming
- Programming Paradigms