Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

reverseEach implemented, tests, fixes #135

+ Hinting fixes
  • Loading branch information...
commit 900c472d2613f5d8e9d2a906548a2106b448a79d 1 parent 31f2cdc
@alexgraul alexgraul authored iros committed
View
2  src/importers/remote.js
@@ -147,7 +147,7 @@
}
if (!paramStr && !isScript) {
- url += "?"
+ url += "?";
}
if ( !paramStr || !/callback/.test(paramStr) ) {
View
21 src/parsers/delimited.js
@@ -46,14 +46,15 @@
var columns = [],
columnData = {},
uniqueSequence = {};
- uniqueId = function(str) {
- if ( !uniqueSequence[str] ) {
- uniqueSequence[str] = 0;
- }
- var id = str + uniqueSequence[str];
- uniqueSequence[str] += 1;
- return id;
- }
+
+ var uniqueId = function(str) {
+ if ( !uniqueSequence[str] ) {
+ uniqueSequence[str] = 0;
+ }
+ var id = str + uniqueSequence[str];
+ uniqueSequence[str] += 1;
+ return id;
+ };
var parseCSV = function(delimiterPattern, strData, strDelimiter, skipRows, emptyValue) {
@@ -177,13 +178,13 @@
} else {
- function createColumnName(start) {
+ var createColumnName = function(start) {
var newName = uniqueId(start);
while ( columns.indexOf(newName) !== -1 ) {
newName = uniqueId(start);
}
return newName;
- }
+ };
//No column name? Create one starting with X
if ( _.isUndefined(strMatchedValue) || strMatchedValue === '' ) {
View
15 src/view.js
@@ -391,7 +391,7 @@
* iterator - function that is passed each row
* iterator(rowObject, index, dataset)
* context - options object. Optional.
- */
+ */
each : function(iterator, context) {
for(var i = 0; i < this.length; i++) {
iterator.apply(context || this, [this.rowByPosition(i), i]);
@@ -399,6 +399,19 @@
},
/**
+ * Iterates over all rows in the dataset in reverse order
+ * Parameters:
+ * iterator - function that is passed each row
+ * iterator(rowObject, index, dataset)
+ * context - options object. Optional.
+ */
+ reverseEach : function(iterator, context) {
+ for(var i = this.length-1; i >= 0; i--) {
+ iterator.apply(context || this, [this.rowByPosition(i), i]);
+ }
+ },
+
+ /**
* Iterates over each column.
* Parameters:
* iterator - function that is passed:
View
37 test/unit/views.js
@@ -200,6 +200,43 @@
module("Views :: Rows Selection");
+ test("each", function() {
+ var ds = Util.baseSample();
+ var expectedRow = {
+ _id : ds._columns[0].data[0],
+ one : 1,
+ two : 4,
+ three : 7
+ };
+
+ ds.each(function(row, index) {
+ if (index === 0) {
+ ok(_.isEqual(row, expectedRow), "Row by position is equal");
+ }
+ });
+
+ });
+
+
+ test("reversed each", 1, function() {
+ var ds = Util.baseSample();
+ var expectedRow = {
+ _id : ds._columns[0].data[2],
+ one : 3,
+ two : 6,
+ three : 9
+ };
+ var count = 0;
+
+ ds.reverseEach(function(row, index) {
+ console.log(row, index);
+ if (count === 0) {
+ ok(_.isEqual(row, expectedRow), "Row by position is equal");
+ }
+ count += 1;
+ });
+ });
+
test("Get row by position", function() {
var ds = Util.baseSample();
var row = ds.rowByPosition(0);
Please sign in to comment.
Something went wrong with that request. Please try again.