微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Linq Aggregate给出了空值,而不是预期的回报列表

如何解决Linq Aggregate给出了空值,而不是预期的回报列表

我正在尝试使用linq聚合来模仿减少行为。我需要//We define a graph class Node { constructor() { //hash map this.connections = new Map() //attributes this.attributes = new Map() } } class Graph { constructor() { //get nodes this.nodes = new Node() } //Add node addNode(node) { this.nodes.connections.set(node,[]) this.nodes.attributes.set(node,[]) } addNodeAttribute(node,attribute) { //set a node attribute this.nodes.attributes.get(node).push(attribute) } //Create an edge addEdge(source,destination) { //if A is friend with B,b is friends with A //undirected this.nodes.connections.get(source).push(destination) this.nodes.connections.get(destination).push(source) } breadthFirstSearch(startingNode) { let visitednodes = [] let queue = [] visitednodes[startingNode] = true queue.push(startingNode) while (queue.length > 0) { const currentNode = queue.shift() //takes the first element const connections = this.nodes.connections.get(currentNode) if (this.nodes.attributes.get(currentNode) == "Mango") { return currentNode } for (let node of connections) { if(!visitednodes[node]) { //if not visited visitednodes[node] = true //then true queue.push(node) //push node } } } return "no mango sellers" } } let graph = new Graph() //Create nodes graph.addNode("Nicolai") graph.addNode("Alice") graph.addNode("Claire") graph.addNode("Peggy") graph.addNode("Bob") graph.addNode("Anuj") graph.addNode("Jonny") graph.addNode("Thom") //selling mangoer graph.addNodeAttribute("Thom","Mango") //add edeges graph.addEdge("Nicolai","Bob") graph.addEdge("Nicolai","Claire") graph.addEdge("Nicolai","Alice") graph.addEdge("Alice","Peggy") graph.addEdge("Bob","Peggy" ) graph.addEdge("Bob","Anuj") graph.addEdge("Claire","Thom") graph.addEdge("Claire","Jonny") console.log(graph.nodes.connections) 返回数组列表。出于某种原因,GroupingMethod无论如何都返回null。感谢您的帮助。

GroupingMethod

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。