Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b6b4d6a

Browse files
Merge pull request #69 from someyoungideas/isIntegers
initial commit implementing isIntegers
2 parents 35370f3 + 4fbc9e8 commit b6b4d6a

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ List of possible functions and their implementation status, compiled by [@D1esel
6868
General Types:
6969

7070
- [ ] Natural numbers
71-
- [] Integers
71+
- [x] Integers
7272
- [ ] Rational numbers
7373
- [ ] Irrational numbers
7474
- [ ] Real numbers

‎index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = Object.assign(
1616
require('./lib/floatPrecise.js'),
1717
require('./lib/isAscending.js'),
1818
require('./lib/isDescending.js'),
19+
require('./lib/isIntegers.js'),
1920
require('./lib/isPrime.js'),
2021
require('./lib/isComposit.js'),
2122
require('./lib/maximum.js'),

‎lib/isIntegers.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* This function evaluates whether all parameters are integers
3+
* @memberof variadic
4+
* @author someyoungideas
5+
* @param {...*} params - One or more parameters.
6+
*/
7+
exports.isIntegers = (...params) => {
8+
if (params.length === 0) throw Error('Please provide at least one number to evaluate isInteger.');
9+
if (params.some(param => Number.isNaN(Number.parseFloat(param)))) throw Error('Please provide all numbers to evaluate isInteger.');
10+
if (params.some(param => !Number.isInteger(Number.parseFloat(param)))) return false;
11+
12+
return true;
13+
};

‎package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎spec/isIntegersSpec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const { isIntegers } = require('../lib/isIntegers');
2+
3+
describe('isIntegers', () => {
4+
it('should throw an error if no parameters are provided', () => {
5+
expect(() => isIntegers()).toThrow();
6+
});
7+
8+
it('should throw an error if any parameters provided are not numbers', () => {
9+
expect(() => isIntegers('')).toThrow();
10+
expect(() => isIntegers('test', 2)).toThrow();
11+
});
12+
13+
it('should return false if any parameters are not an integer', () => {
14+
expect(isIntegers(2.5)).toBe(false);
15+
expect(isIntegers(2, 2.5)).toBe(false);
16+
});
17+
18+
it('should return true if all parameters are integers', () => {
19+
expect(isIntegers(0)).toBe(true);
20+
expect(isIntegers(2)).toBe(true);
21+
expect(isIntegers(-1)).toBe(true);
22+
expect(isIntegers(-1, 0, 2)).toBe(true);
23+
});
24+
25+
it('should return true if all parameters can parse to integer', () => {
26+
expect(isIntegers('0')).toBe(true);
27+
expect(isIntegers('2')).toBe(true);
28+
expect(isIntegers('-1')).toBe(true);
29+
expect(isIntegers('-1', '0', '2')).toBe(true);
30+
expect(isIntegers('-1', 0, '2')).toBe(true);
31+
});
32+
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /