Skip to content

Commit

Permalink
Force size and step to be integers
Browse files Browse the repository at this point in the history
  • Loading branch information
csbailey5t committed Dec 9, 2015
1 parent 387ecdb commit be33fe7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions app/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
(function($) {
'use strict';

// TODO: Switch these based on development or production
zip.workerScriptsPath = '/chunk-corpus/scripts/';
// zip.workerScriptsPath = '/scripts/';

Expand Down Expand Up @@ -45,18 +46,21 @@

// return { start: ...., data: .... }
var chunk = function(xs, size, step) {

var output = [],
i = 0;
i = 0,
stepInt = +step,
sizeInt = +size;

if (xs.length < size) {
if (xs.length < sizeInt) {
output.push(xs);
} else {
while (i <= xs.length) {
output.push({
start: i,
data: xs.slice(i, i + size)
data: xs.slice(i, i + sizeInt)
});
i += step;
i += stepInt;
}
}

Expand Down Expand Up @@ -94,7 +98,7 @@
return Bacon.fromCallback(function(callback) {
zip.createWriter(new zip.BlobWriter(), function(writer) {
zipAdd(writer, files, 0, callback);
});
}, function(error) { console.log(error); });
});
};

Expand Down Expand Up @@ -142,8 +146,8 @@
.flatMap(readTextFile)
.map(over('contents', tokenize))
.map(over('contents', function(tokens) {
var chunks = chunk(tokens, size, step),
progress = $('#chunk_progress');
var chunks = chunk(tokens, size, step);
var progress = $('#chunk_progress');
progress
.attr('max', chunks.length + parseInt(progress.attr('max')) - 1);
return chunks;
Expand Down

0 comments on commit be33fe7

Please sign in to comment.