Skip to content

Commit 99febd3

Browse files
committed
vectorFactory returns unprocessed rule as well for easier mapping
1 parent 8a90a96 commit 99febd3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

css-simplify.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var css = require('css'),
66
var cumulativeComparisonVectorFactoryFactory = function() {
77

88
var dict = {},
9-
dictlength = 0;
9+
dictlength = 0;
1010

1111
return function(rule) {
1212
var vector = Array.apply(null, Array(dictlength)).map(Number.prototype.valueOf, 0);
@@ -20,7 +20,7 @@ var cumulativeComparisonVectorFactoryFactory = function() {
2020
}
2121
});
2222

23-
return vector;
23+
return { 'vector': vector, 'rule': rule };
2424
};
2525
};
2626

@@ -42,7 +42,7 @@ var rankVectors = function (vectors) {
4242
for (var j = 0; j < length; ++j ) {
4343
ranks[j] = [];
4444

45-
for (var i = 0; i < length; ++i) {
45+
for (var i = 0; i <= j; ++i) {
4646
if ( i === j ) {
4747
ranks[j][i] = 0;
4848
continue;
@@ -56,16 +56,20 @@ var rankVectors = function (vectors) {
5656

5757

5858
var vecfac = cumulativeComparisonVectorFactoryFactory(),
59+
processedRules = null,
5960
vectors = null;
6061

6162
// lets go:
6263
fs.readFile('lol.css', 'utf8', function (err, res) {
6364
if (res !== null) {
64-
vectors = _.map(_.filter(css.parse(res).stylesheet.rules, function(x) { return x.type === 'rule';}), vecfac);
65+
processedRules = _.map(_.filter(css.parse(res).stylesheet.rules, function(x) { return x.type === 'rule';}), vecfac);
6566
} else {
6667
console.log('ERROR');
6768
console.log(err);
6869
}
70+
71+
vectors = _.map(processedRules, function(rule) { return rule.vector });
72+
6973
if (vectors === null) {
7074
console.log('vectors is null');
7175
process.exit();

0 commit comments

Comments
 (0)