|
18 | 18 | *
|
19 | 19 | *@private
|
20 | 20 | *@param {array} inputGraph The input matrix of the graph
|
21 |
| - *@param {number} destination The destination |
| 21 | + *@param {array} destination The destination |
22 | 22 | */
|
23 | 23 | functioninit(inputGraph,destination){
|
24 | 24 | graph=inputGraph;
|
|
27 | 27 | visited={};
|
28 | 28 | }
|
29 | 29 |
|
| 30 | +/** |
| 31 | + * Adds a valid node to the queue |
| 32 | + *@param {array} node Node to be added to the queue |
| 33 | + */ |
30 | 34 | functionaddNode(node){
|
31 | 35 | if(visited[node]||
|
32 | 36 | node[0]<0||node[1]<0||
|
|
40 | 44 | /**
|
41 | 45 | * Process given node
|
42 | 46 | *
|
43 |
| - *@param {number} destination The destionation, which should be reached |
44 |
| - *@param {number} current The current node |
45 |
| - *@param {number} node Neighbour node |
| 47 | + *@param {array} destination The destionation, which should be reached |
| 48 | + *@param {array} current The current node |
46 | 49 | */
|
47 | 50 | functionprocessNode(destination,current){
|
48 | 51 | if(destination.toString()===current.toString()){
|
|
57 | 60 | }
|
58 | 61 |
|
59 | 62 | /**
|
60 |
| - * Validates thegraph |
| 63 | + * Validates theparams |
61 | 64 | *
|
62 | 65 | *@param {array} graph A matrix representation of the graph
|
63 |
| - *@param {number} source The source node |
64 |
| - *@param {number} destination The destination node |
65 |
| - *@returns {boolean} true/false depending whether the params are valid |
| 66 | + *@param {array} source The source node |
| 67 | + *@param {array} destination The destination node |
66 | 68 | */
|
67 | 69 | functionvalidateParams(graph,source,destination){
|
68 | 70 | if(!graph){
|
69 |
| -throw'The graph should be represented as a matrix'; |
| 71 | +thrownewError('The graph should be represented as a matrix'); |
70 | 72 | }
|
71 |
| -if(!graph[0]){ |
72 |
| -throw'The graph should be represented as '+ |
73 |
| -'a matrix, with size at least 1x1'; |
| 73 | +if(graph[0]===undefined){ |
| 74 | +thrownewError('The graph should be represented as '+ |
| 75 | +'a matrix, with size at least 1x1'); |
74 | 76 | }
|
75 | 77 | varwidth=graph[0].length;
|
76 |
| -for(vari=0;i<graph.length;i+=1){ |
77 |
| -if(graph[i]!==width){ |
78 |
| -throw'The graph should be represented as a matrix'; |
| 78 | +for(vari=1;i<graph.length;i+=1){ |
| 79 | +if(graph[i].length!==width){ |
| 80 | +thrownewError('The graph should be represented as a matrix'); |
79 | 81 | }
|
80 | 82 | }
|
81 | 83 | source.concat(destination).filter(function(c,i){
|
82 | 84 | if(c<0){
|
83 |
| -throw'The source and destination coordinates should be above zero'; |
| 85 | +thrownewError('The source and destination coordinates '+ |
| 86 | +'should be above zero'); |
84 | 87 | }
|
85 | 88 | if(i%2===0){
|
86 | 89 | if(c>=graph.length){
|
87 |
| -throw'The source and destination coordinates '+ |
88 |
| -'should not be above graph\'s size'; |
| 90 | +thrownewError('The source and destination coordinates '+ |
| 91 | +'should not be above graph\'s size'); |
89 | 92 | }
|
90 | 93 | }else{
|
91 | 94 | if(c>=graph[0].length){
|
92 |
| -throw'The source and destination coordinates '+ |
93 |
| -'should not be above graph\'s size'; |
| 95 | +thrownewError('The source and destination coordinates '+ |
| 96 | +'should not be above graph\'s size'); |
94 | 97 | }
|
95 | 98 | }
|
96 | 99 | });
|
|