src/js/extensions/chart/chart.js
function _reduceToTSV(arr) {
  // 2D array => quoted TSV row array
  // [['a', 'b b'], [1, 2]] => ['a\t"b b"', '1\t2']
  return arr.reduce((acc, row) => {
    // ['a', 'b b', 'c c'] => ['a', '"b b"', '"c c"']
    const quoted = row.map(text => {
      if (!isNumeric(text) && text.indexOf(' ') >= 0) {
        text = `"${text}"`;
      }

      return text;
    });
    // ['a', '"b b"', '"c c"'] => 'a\t"b b"\t"c c"'
    acc.push(quoted.join('\t'));

    return acc;
  }, []);
}
function _reduceToTSV(arr) {
  // 2D array => quoted TSV row array
  // [['a', 'b b'], [1, 2]] => ['a\t"b b"', '1\t2']
  return arr.reduce((acc, row) => {
    // ['a', 'b b', 'c c'] => ['a', '"b b"', '"c c"']
    const quoted = row.map(text => {
      if (!isNumeric(text) && text.indexOf(' ') >= 0) {
        text = `"${text}"`;
      }

      return text;
    });
    // ['a', '"b b"', '"c c"'] => 'a\t"b b"\t"c c"'
    acc.push(quoted.join('\t'));

    return acc;
  }, []);
}
function _reduceToTSV ( arr ) { // 2D array => quoted TSV row array // [['a', 'b b'], [1, 2]] => ['a\t"b b"', '1\t2'] return arr . reduce ( ( acc , row ) => { // ['a', 'b b', 'c c'] => ['a', '"b b"', '"c c"'] const quoted = row . map ( text => { if ( ! isNumeric ( text ) && text . indexOf ( ' ' ) >= 0 ) { text = ` ${ text } ` ; } return text ; } ) ; // ['a', '"b b"', '"c c"'] => 'a\t"b b"\t"c c"' acc . push ( quoted . join ( '\t' ) ) ; return acc ; } , [ ] ) ; }
reduce 2D array to TSV rows
@param {Array.<Array.<string>>} arr - 2d array
@returns {Array.<string>} - TSV row array
@ignore
reduce 2D array to TSV rows