Permalink
Browse files

refactor printMatrix to use deepZipWith

  • Loading branch information...
1 parent 0c7b1bc commit d6307dce1217913f2208fe39fdba72610b29b7f3 Stephanie H. Chang committed Oct 4, 2012
Showing with 10 additions and 9 deletions.
  1. +10 −9 utils/matrix.js
View
@@ -40,16 +40,17 @@ $.extend(KhanUtil, {
mat2[0].length === mat[0].length &&
_.isString(color2) && _.isString(operation));
+ if (isCombo) {
+ mat = KhanUtil.deepZipWith(2, function(a, b) {
+ var elem1 = "\\color{" + color + "}{" + a + "}";
+ var elem2 = "\\color{" + color2 + "}{" + b + "}";
+ return elem1 + operation + elem2;
+ }, mat, mat2);
+ }
+
var table = _.map(mat, function(row, i) {
- if (isCombo) {
- row = _.map(row, function(elem, j) {
- var elem1 = "\\color{" + color + "}{" + elem + "}";
- var elem2 = "\\color{" + color2 + "}{" + mat2[i][j] + "}";
- return elem1 + operation + elem2;
- });
- }
- return row.join(" & ");
- }).join(" \\\\ ");
+ return row.join(" & ");
+ }).join(" \\\\ ");
var prefix = "\\left[ \\begin{array}";
var suffix = "\\end{array} \\right]";

0 comments on commit d6307dc

Please sign in to comment.