We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7b7abe7 commit f35852bCopy full SHA for f35852b
.gitignore
@@ -2,3 +2,6 @@ lib/*
2
node_modules/**
3
yarn.lock
4
package-lock.json
5
+builder/**
6
+coverage/**
7
+.nyc_output/**
.travis.yml
@@ -0,0 +1,14 @@
1
+language: node_js
+node_js:
+ - "7"
+cache:
+ yarn: true
+
+install:
8
+ - yarn install
9
10
+script:
11
+ - REPORT=lcov make test
12
13
+after_success:
14
+ - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
Makefile
@@ -17,9 +17,6 @@ dist-all: pre-build dist/range.js dist/range.min.js lib/range.js
17
18
all: test dist-all lib/range.js
19
20
-test:
21
- $(MOCHA) $(TEST_CFLAGS) tests/*.js
22
-
23
clean:
24
rm -rf lib dist
25
builder
package.json
@@ -16,7 +16,15 @@
16
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
+ "coveralls": "^2.13.1",
+ "istanbul": "^0.4.5",
"mocha": "^3.5.0",
+ "nyc": "^11.2.1",
"should": "^12.0.0"
+ },
+ "nyc": {
26
+ "exclude": [
27
+ "tests/*.js"
28
+ ]
29
}
30
src/index.js
@@ -11,9 +11,9 @@ export const rangeIn = (start, end, range) =>
export const rangeImpl = (start, end, step, f) => {
const length = end - start;
- const elements = step > 1 ?
15
- (length - (step == 1 ? 0 : Math.round(length / step))) :
- Math.round(length / step);
+ if (length == 0 || step == 0) { return []; }
+ const steps = Math.round(length / step);
+ const elements = step > 1 ? (length - steps) : steps;
const ls = new Array(elements);
for (let i = 0; i < length && i <= elements; i++) {
ls[i] = f((i * step) + start);
@@ -27,7 +27,7 @@ export const rangeChar = (start, end) => {
let ok = rangeIn(x, y, charLowerRange) ||
rangeIn(x, y, charUpperRange) ||
rangeIn(x, y, charNumberRange);
- return ok ? rangeImpl( x, y + 1, 1, String.fromCharCode) : [];
+ return ok ? rangeImpl(x, y + 1, 1, String.fromCharCode) : [];
31
};
32
33
export const rangeStep = (start, end, step) =>
tests/index.js
@@ -4,7 +4,7 @@ import * as R from '../src/index.js';
describe("range", () => {
context("numeric", () => {
- it("empty range.", () => {
+ it("zero range.", () => {
R.range(0, 0).should.be.eql([]);
});
@@ -34,6 +34,14 @@ describe("range", () => {
34
it("[1..10), 2", () => {
35
R.rangeStep(1, 10, 2).length.should.be.eql(5);
36
37
38
+ it("[1..10]", () => {
39
+ R.rangeInclStep(1, 10, 2).length.should.be.eql(6);
40
+ });
41
42
+ it("zero step should return empty list.", () => {
43
+ R.rangeImpl(1, 1, 0).should.be.eql([]);
44
45
46
47
0 commit comments