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

analyzeNumber - add tests for positive, negative, and zero cases #508

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
41 changes: 41 additions & 0 deletions 13_analyzeNumber/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Exercise 13 - analyzeNumber

Description of the exercise goes here.

## Task

Write a function `analyzeNumber` that takes a single number as an argument and returns an object with two properties:

1. `type`: A string indicating whether the number is `"positive"`, `"negative"`, or `"zero"`.
2. `parity`: A string indicating whether the number is `"even"` or `"odd"`.

### Examples

```javascript
analyzeNumber(5); // { type: "positive", parity: "odd" }
analyzeNumber(-8); // { type: "negative", parity: "even" }
analyzeNumber(0); // { type: "zero", parity: "even" }


---

### 2. **`analyzeNumber.js`**

```javascript
function analyzeNumber(number) {
let type;

if (number > 0) {
type = 'positive';
} else if (number < 0) {
type = 'negative';
} else {
type = 'zero';
}

const parity = number % 2 === 0 ? 'even' : 'odd';

return { type, parity };
}

module.exports = analyzeNumber;
11 changes: 11 additions & 0 deletions 13_analyzeNumber/analyzeNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function analyzeNumber(num) {
if (num > 0) {
return 'positive';
} else if (num < 0) {
return 'negative';
} else {
return 'zero';
}
}

module.exports = analyzeNumber;
13 changes: 13 additions & 0 deletions 13_analyzeNumber/analyzeNumber.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const analyzeNumber = require('./analyzeNumber');

test('returns "positive" for positive numbers', () => {
expect(analyzeNumber(5)).toBe('positive');
});

test('returns "negative" for negative numbers', () => {
expect(analyzeNumber(-3)).toBe('negative');
});

test('returns "zero" for zero', () => {
expect(analyzeNumber(0)).toBe('zero');
});
11 changes: 11 additions & 0 deletions 13_analyzeNumber/solution/analyzeNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function analyzeNumber(num) {
if (num > 0) {
return 'positive';
} else if (num < 0) {
return 'negative';
} else {
return 'zero';
}
}

module.exports = analyzeNumber;
13 changes: 13 additions & 0 deletions 13_analyzeNumber/solution/analyzeNumber.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const analyzeNumber = require('./analyzeNumber');

test('returns "positive" for positive numbers', () => {
expect(analyzeNumber(5)).toBe('positive');
});

test('returns "negative" for negative numbers', () => {
expect(analyzeNumber(-3)).toBe('negative');
});

test('returns "zero" for zero', () => {
expect(analyzeNumber(0)).toBe('zero');
});