Browse Source

[misc] Minor changes

master
Muthu Kumar 6 years ago
parent
commit
c8da648780
  1. 3
      .gitignore
  2. 15
      es5/infinity.js
  3. 21
      index.js

3
.gitignore

@ -1 +1,2 @@
node_modules node_modules
example.js

15
es5/infinity.js

@ -211,20 +211,19 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var source = void 0, var source = void 0,
target = void 0; target = void 0;
// "from" number of elements
if (isNonZeroFalsy(to)) { if (isNonZeroFalsy(to)) {
// "from" number of elements
source = 0; source = 0;
target = from; target = from;
} } else {
// "target" is the end index! // "target" is the end index!
else { source = from;
source = from; target = to + 1;
target = to + 1; };
};
for (var i = source; i < target; i++) { for (var i = source; i < target; i++) {
arr.push(this.get(i)); arr.push(this.get(i));
}; }
return arr; return arr;
}; };

21
index.js

@ -50,7 +50,7 @@ class InfiniteListItem {
return ('InfiniteListItem [ .. ' + return ('InfiniteListItem [ .. ' +
stringify(this.value) + stringify(this.value) +
' .. ]') ' .. ]')
}; }
} }
class InfiniteList { class InfiniteList {
@ -90,7 +90,7 @@ class InfiniteList {
if (!cache[0]) cache[0] = start; if (!cache[0]) cache[0] = start;
// If index were to be infinity, value and index are infinity // If index were to be infinity, value and index are infinity
if (index === Infinity) return new InfiniteListItem(this, Infinity, Infinity) if (index === Infinity) return new InfiniteListItem(this, Infinity, Infinity);
// If index exists in cache, return the value // If index exists in cache, return the value
if (index in cache) return new InfiniteListItem(this, cache[index], index); if (index in cache) return new InfiniteListItem(this, cache[index], index);
@ -124,7 +124,7 @@ class InfiniteList {
done: false, done: false,
value: this.get(j++) value: this.get(j++)
}) })
} };
}; };
} }
} }
@ -146,20 +146,19 @@ InfiniteList.prototype.take = function (from, to) {
) return arr; ) return arr;
let source, target; let source, target;
// "from" number of elements
if (isNonZeroFalsy(to)) { if (isNonZeroFalsy(to)) {
// "from" number of elements
source = 0; source = 0;
target = from; target = from;
} } else {
// "target" is the end index! // "target" is the end index!
else {
source = from; source = from;
target = to + 1 target = to + 1
}; };
for (let i = source; i < target; i++) { for (let i = source; i < target; i++) {
arr.push(this.get(i)); arr.push(this.get(i));
}; }
return arr; return arr;
}; };
@ -168,7 +167,7 @@ InfiniteList.prototype.take = function (from, to) {
* @returns {InfiniteListItem} Instance of InfiniteListItem * @returns {InfiniteListItem} Instance of InfiniteListItem
*/ */
InfiniteList.prototype.top = function () { InfiniteList.prototype.top = function () {
return this.get(0) return this.get(0);
}; };
/** /**
@ -176,7 +175,7 @@ InfiniteList.prototype.top = function () {
* @returns {InfiniteListItem} Instance of InfiniteListItem * @returns {InfiniteListItem} Instance of InfiniteListItem
*/ */
InfiniteList.prototype.end = function () { InfiniteList.prototype.end = function () {
return this.get(Infinity) return this.get(Infinity);
}; };
/** /**
@ -195,7 +194,7 @@ InfiniteList.prototype.toString = function () {
'... ]' '... ]'
] ]
.join(' '); .join(' ');
} };
/* Convenience methods */ /* Convenience methods */
InfiniteList.prototype.first = InfiniteList.prototype.top; InfiniteList.prototype.first = InfiniteList.prototype.top;

Loading…
Cancel
Save