{"size": 2991, "ext": "js", "max_stars_repo_path": "lib/bfs.js", "max_stars_repo_name": "OronNadiv/bfs-as-promised", "max_stars_repo_stars_event_min_datetime": "2020-01-22T18:16:16.000Z", "max_stars_repo_stars_event_max_datetime": "2020-01-22T18:16:16.000Z", "max_issues_repo_path": "lib/bfs.js", "max_issues_repo_name": "OronNadiv/bfs-as-promised", "max_issues_repo_issues_event_min_datetime": "2017-12-30T10:12:51.000Z", "max_issues_repo_issues_event_max_datetime": "2017-12-30T10:12:51.000Z", "max_forks_repo_path": "lib/bfs.js", "max_forks_repo_name": "OronNadiv/bfs-as-promised", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 1495.5, "max_line_length": 2959, "alphanum_fraction": 0.7913741224}
'use strict';var _typeof=typeof Symbol==='function'&&typeof Symbol.iterator==='symbol'?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==='function'&&obj.constructor===Symbol?'symbol':typeof obj};var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if('value'in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError('Cannot call a class as a function')}}var Promise=require('bluebird');var BFS=function(){function BFS(start,getMoves,isGoal){_classCallCheck(this,BFS);this.start=start;this.getMoves=getMoves;this.isGoal=isGoal;this.visited=new Map;this.visited.set(start,null);this.queue=new Set;this.queue.add(start)}_createClass(BFS,[{key:'_returnPath',value:function _returnPath(){var self=this;if(self.final===undefined){return null}var currentItem=self.final;var path=[];do{path.splice(0,0,currentItem);currentItem=self.visited.get(currentItem)}while(currentItem!==self.start);path.splice(0,0,currentItem);return path}},{key:'_fetchAdjutant',value:function _fetchAdjutant(fromNodes,depth){return Promise.resolve(this.getMoves(fromNodes,depth)).tap(function(map){if((typeof map==='undefined'?'undefined':_typeof(map))!=='object'){throw new Error('Unexpected result from getMoves.\nExpected type: Object.\nActual type: '+(typeof map==='undefined'?'undefined':_typeof(map))+', value: '+map)}if(map.size!==fromNodes.length){throw new Error('Unexpected result from getMoves.\nExpected count: '+fromNodes.length+'.\nActual count: '+map.size)}})}},{key:'_checkIsGoal',value:function _checkIsGoal(fromNode,toNodes){var self=this;return Promise.map(toNodes,function(toNode){if(toNode===null||toNode===undefined||self.visited.has(toNode)){return}self.visited.set(toNode,fromNode);return Promise.resolve(self.isGoal(toNode)).then(function(isGoal){if(isGoal){self.final=toNode;self.isDone=true;return}self.queue.add(toNode)})})}},{key:'_processQueue',value:function _processQueue(depth){var self=this;if(self.isDone||self.queue.size===0){return Promise.resolve()}return Promise.resolve(self._fetchAdjutant(Array.from(self.queue),depth)).then(function(map){self.queue.clear();var promises=[];map.forEach(function(toNodes,fromNode){promises.push(self._checkIsGoal(fromNode,toNodes,depth))});return Promise.all(promises)}).then(function(){return self._processQueue(depth+1)})}},{key:'find',value:function find(){var self=this;return Promise.resolve(self._processQueue(0)).then(function(){return self._returnPath()})}}]);return BFS}();module.exports=BFS;
//# sourceMappingURL=bfs.js.map