From 9e36d35b20c659a1395f1e8c0a88ffdef36f5062 Mon Sep 17 00:00:00 2001 From: Brian Mearns Date: Fri, 28 Sep 2018 11:22:20 -0400 Subject: [PATCH] Ensure length is non-negative This can happen when finish and start are 0, and step is -1. Length should be 0, but is calculated as -0. This is strange behavior, and caused a unit test to fail because the generated array length was 0, which did not assert as equal to the calculated range length or -0. --- package-lock.json | 332 ++++++++++++++++++++++++++++++++++++++++++++++ xrange.js | 2 +- 2 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 package-lock.json diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..9b8ffa7 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,332 @@ +{ + "name": "xrange", + "version": "1.0.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "balanced-match": { + "version": "1.0.0", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/balanced-match/-/balanced-match-1.0.0.tgz?dl=https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "dev": true + }, + "brace-expansion": { + "version": "1.1.11", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/brace-expansion/-/brace-expansion-1.1.11.tgz?dl=https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha1-PH/L9SnYcibz0vUrlm/1Jx60Qd0=", + "dev": true, + "requires": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "cli": { + "version": "0.4.5", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/cli/-/cli-0.4.5.tgz?dl=https://registry.npmjs.org/cli/-/cli-0.4.5.tgz", + "integrity": "sha1-ePlIXNFhtWbppsctcXDEJw6B22E=", + "dev": true, + "requires": { + "glob": ">= 3.1.4" + } + }, + "commander": { + "version": "0.6.1", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/commander/-/commander-0.6.1.tgz?dl=http://registry.npmjs.org/commander/-/commander-0.6.1.tgz", + "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=", + "dev": true + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/concat-map/-/concat-map-0.0.1.tgz?dl=https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "dev": true + }, + "console-browserify": { + "version": "0.1.6", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/console-browserify/-/console-browserify-0.1.6.tgz?dl=https://registry.npmjs.org/console-browserify/-/console-browserify-0.1.6.tgz", + "integrity": "sha1-0SijwLuINQ61YmxufHGm8P1ImDw=", + "dev": true + }, + "debug": { + "version": "4.0.1", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/debug/-/debug-4.0.1.tgz?dl=https://registry.npmjs.org/debug/-/debug-4.0.1.tgz", + "integrity": "sha1-+bs21Dm40fDdUtj7a0bk67jBzVs=", + "dev": true, + "requires": { + "ms": "^2.1.1" + }, + "dependencies": { + "ms": { + "version": "2.1.1", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/ms/-/ms-2.1.1.tgz?dl=https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha1-MKWGTrPrsKZvLr5tcnrwagnYbgo=", + "dev": true + } + } + }, + "diff": { + "version": "1.0.2", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/diff/-/diff-1.0.2.tgz?dl=https://registry.npmjs.org/diff/-/diff-1.0.2.tgz", + "integrity": "sha1-Suc/Gu6Nb89ITxoc53zmUdm38Mk=", + "dev": true + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/fs.realpath/-/fs.realpath-1.0.0.tgz?dl=https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "dev": true + }, + "glob": { + "version": "7.1.3", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/glob/-/glob-7.1.3.tgz?dl=https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", + "integrity": "sha1-OWCDLT8VdBCDQtr9OmezMsCWnfE=", + "dev": true, + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "dependencies": { + "minimatch": { + "version": "3.0.4", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/minimatch/-/minimatch-3.0.4.tgz?dl=https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha1-UWbihkV/AzBgZL5Ul+jbsMPTIIM=", + "dev": true, + "requires": { + "brace-expansion": "^1.1.7" + } + } + } + }, + "graceful-fs": { + "version": "1.2.3", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/graceful-fs/-/graceful-fs-1.2.3.tgz?dl=https://registry.npmjs.org/graceful-fs/-/graceful-fs-1.2.3.tgz", + "integrity": "sha1-FaSAaldUfLLS2/J/QuiajDRRs2Q=", + "dev": true + }, + "growl": { + "version": "1.7.0", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/growl/-/growl-1.7.0.tgz?dl=https://registry.npmjs.org/growl/-/growl-1.7.0.tgz", + "integrity": "sha1-3i1mE20ALhErpw8/EMMc98NQsto=", + "dev": true + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/inflight/-/inflight-1.0.6.tgz?dl=https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/inherits/-/inherits-2.0.3.tgz?dl=https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "dev": true + }, + "jade": { + "version": "0.26.3", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/jade/-/jade-0.26.3.tgz?dl=https://registry.npmjs.org/jade/-/jade-0.26.3.tgz", + "integrity": "sha1-jxDXl32NefL2/4YqgbBRPMslaGw=", + "dev": true, + "requires": { + "commander": "0.6.1", + "mkdirp": "0.3.0" + }, + "dependencies": { + "mkdirp": { + "version": "0.3.0", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/mkdirp/-/mkdirp-0.3.0.tgz?dl=http://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz", + "integrity": "sha1-G79asbqCevI1dRQ0kEJkVfSB/h4=", + "dev": true + } + } + }, + "jshint": { + "version": "2.1.11", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/jshint/-/jshint-2.1.11.tgz?dl=https://registry.npmjs.org/jshint/-/jshint-2.1.11.tgz", + "integrity": "sha1-61EI/vm6Xd67gwmD9XLSQuSeP5Y=", + "dev": true, + "requires": { + "cli": "0.4.x", + "console-browserify": "0.1.x", + "minimatch": "0.x.x", + "shelljs": "0.1.x", + "underscore": "1.4.x" + } + }, + "keypress": { + "version": "0.1.0", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/keypress/-/keypress-0.1.0.tgz?dl=https://registry.npmjs.org/keypress/-/keypress-0.1.0.tgz", + "integrity": "sha1-SjGI1CkbZrT2XtuZ+AaqmuKTWSo=", + "dev": true + }, + "lru-cache": { + "version": "2.7.3", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/lru-cache/-/lru-cache-2.7.3.tgz?dl=https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", + "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", + "dev": true + }, + "minimatch": { + "version": "0.4.0", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/minimatch/-/minimatch-0.4.0.tgz?dl=https://registry.npmjs.org/minimatch/-/minimatch-0.4.0.tgz", + "integrity": "sha1-vSx9Bg0sjI/Xzefx8u0tWycP2xs=", + "dev": true, + "requires": { + "lru-cache": "2", + "sigmund": "~1.0.0" + } + }, + "mkdirp": { + "version": "0.3.5", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/mkdirp/-/mkdirp-0.3.5.tgz?dl=http://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz", + "integrity": "sha1-3j5fiWHIjHh+4TaN+EmsRBPsqNc=", + "dev": true + }, + "mocha": { + "version": "1.11.0", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/mocha/-/mocha-1.11.0.tgz?dl=http://registry.npmjs.org/mocha/-/mocha-1.11.0.tgz", + "integrity": "sha1-sCjy0wgqFvupk2LMARP4Zmep3a4=", + "dev": true, + "requires": { + "commander": "0.6.1", + "debug": "*", + "diff": "1.0.2", + "glob": "3.2.1", + "growl": "1.7.x", + "jade": "0.26.3", + "mkdirp": "0.3.5", + "ms": "0.3.0" + }, + "dependencies": { + "glob": { + "version": "3.2.1", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/glob/-/glob-3.2.1.tgz?dl=https://registry.npmjs.org/glob/-/glob-3.2.1.tgz", + "integrity": "sha1-V69w7HO6IyO/4/KaBndl22TF11g=", + "dev": true, + "requires": { + "graceful-fs": "~1.2.0", + "inherits": "1", + "minimatch": "~0.2.11" + } + }, + "inherits": { + "version": "1.0.2", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/inherits/-/inherits-1.0.2.tgz?dl=https://registry.npmjs.org/inherits/-/inherits-1.0.2.tgz", + "integrity": "sha1-ykMJ2t7mtUzAuNJH6NfHoJdb3Js=", + "dev": true + }, + "minimatch": { + "version": "0.2.14", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/minimatch/-/minimatch-0.2.14.tgz?dl=https://registry.npmjs.org/minimatch/-/minimatch-0.2.14.tgz", + "integrity": "sha1-x054BXT2PG+aCQ6Q775u9TpqdWo=", + "dev": true, + "requires": { + "lru-cache": "2", + "sigmund": "~1.0.0" + } + } + } + }, + "mocha-phantomjs": { + "version": "3.0.0", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/mocha-phantomjs/-/mocha-phantomjs-3.0.0.tgz?dl=https://registry.npmjs.org/mocha-phantomjs/-/mocha-phantomjs-3.0.0.tgz", + "integrity": "sha1-D/8h1N1/s40ROMwbIVRpSfae2w8=", + "dev": true, + "requires": { + "commander": "~ 1.0.5", + "mocha": "1.9.x" + }, + "dependencies": { + "commander": { + "version": "1.0.5", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/commander/-/commander-1.0.5.tgz?dl=http://registry.npmjs.org/commander/-/commander-1.0.5.tgz", + "integrity": "sha1-RXKVu5duOI6d0NtS3kMz4knz2Iw=", + "dev": true, + "requires": { + "keypress": "0.1.x" + } + }, + "mkdirp": { + "version": "0.3.3", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/mkdirp/-/mkdirp-0.3.3.tgz?dl=http://registry.npmjs.org/mkdirp/-/mkdirp-0.3.3.tgz", + "integrity": "sha1-WV4lHBNww6aLqyE20ONIuBBa3xM=", + "dev": true + }, + "mocha": { + "version": "1.9.0", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/mocha/-/mocha-1.9.0.tgz?dl=http://registry.npmjs.org/mocha/-/mocha-1.9.0.tgz", + "integrity": "sha1-FBBUsTywPOXOWa7OPWXVygG43wo=", + "dev": true, + "requires": { + "commander": "0.6.1", + "debug": "*", + "diff": "1.0.2", + "growl": "1.7.x", + "jade": "0.26.3", + "mkdirp": "0.3.3", + "ms": "0.3.0" + }, + "dependencies": { + "commander": { + "version": "0.6.1", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/commander/-/commander-0.6.1.tgz?dl=http://registry.npmjs.org/commander/-/commander-0.6.1.tgz", + "integrity": "sha1-+mihT2qUXVTbvlDYzbMyDp47GgY=", + "dev": true + } + } + } + } + }, + "ms": { + "version": "0.3.0", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/ms/-/ms-0.3.0.tgz?dl=https://registry.npmjs.org/ms/-/ms-0.3.0.tgz", + "integrity": "sha1-A+3DSNYT5mpWSGz9rFO8vomcvWE=", + "dev": true + }, + "once": { + "version": "1.4.0", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/once/-/once-1.4.0.tgz?dl=https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/path-is-absolute/-/path-is-absolute-1.0.1.tgz?dl=https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "dev": true + }, + "shelljs": { + "version": "0.1.4", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/shelljs/-/shelljs-0.1.4.tgz?dl=https://registry.npmjs.org/shelljs/-/shelljs-0.1.4.tgz", + "integrity": "sha1-37vnjVbDwBaNL7eeEOzR28sH7A4=", + "dev": true + }, + "sigmund": { + "version": "1.0.1", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/sigmund/-/sigmund-1.0.1.tgz?dl=https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", + "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", + "dev": true + }, + "underscore": { + "version": "1.4.4", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/underscore/-/underscore-1.4.4.tgz?dl=https://registry.npmjs.org/underscore/-/underscore-1.4.4.tgz", + "integrity": "sha1-YaajIBBiKvoHljvzJSA88SI51gQ=", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://artifactory.nexus.commercehub.com:443/artifactory/api/npm/npm-virtual/wrappy/-/wrappy-1.0.2.tgz?dl=https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + } + } +} diff --git a/xrange.js b/xrange.js index b462b7f..64b368c 100644 --- a/xrange.js +++ b/xrange.js @@ -1,7 +1,7 @@ (function () { var XRange = function (start, finish, by) { - this.length = Math.ceil((finish - start) / by); + this.length = Math.abs(Math.ceil((finish - start) / by)); this.map = function (callback) { /**