UNPKG

818 BJavaScriptView Raw
1(function() {
2'use strict'
3
4function renderValues(array) {
5 var output = ''
6
7 var width = array[0].length
8 var height = array.length
9
10 var size = '[' + width + '][' + height + ']'
11 var label = size + 'maze values:\n'
12
13 output += label
14
15 // for each line
16 for(var i=0; i < height; i++) {
17 var line = '['
18
19 // for each value in a line
20 for(var j=0; j < array[i].length; j++) {
21 if(array[i][j] < 10) {
22 line += (' ').repeat(2)
23 } else if(array[i][j] < 100) {
24 line += (' ').repeat(1)
25 }
26 line += array[i][j]
27
28 // add a comma
29 if(j < array[i].length - 1) { line += ',' }
30 }
31
32 line += ' ]'
33
34 // add a line break
35 if(i < height - 1) { line += '\n' }
36
37 output += line
38 }
39 console.log(output)
40
41 return output
42}
43
44module.exports = renderValues
45}())