learn-co-curriculum / bfs-lab Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
Solution to test #1 "should return an array of adjacent nodes" accepts
[{name: '23rd&6th', distance: null, predecessor: null}, {name: '28th&Bwy', distance: null, predecessor: null}]
but not
[{name: '28th&Bwy', distance: null, predecessor: null}, {name: '23rd&6th', distance: null, predecessor: null}]
The order of the array received should not matter.
Here is my whole findAdjacent function that works:
`const findAdjacent = (node, verticies, edges) => {
let adjacent = []
edges.forEach(pair => {
if (pair[0] === node) {
adjacent.push(pair[1])
}
if (pair[1] === node) {
adjacent.push(pair[0])
}
})
let nodes = []
while (adjacent.length > 0) {
const name = adjacent.pop()
verticies.forEach(vert => {
if (name === vert.name && vert.distance === null) {
nodes.push(vert)
}
})
}
return nodes.reverse()
}`
and my failing one:
`const findAdjacent = (node, verticies, edges) => {
let adjacent = []
edges.forEach(pair => {
if (pair[0] === node) {
adjacent.push(pair[1])
}
if (pair[1] === node) {
adjacent.push(pair[0])
}
})
let nodes = []
while (adjacent.length > 0) {
const name = adjacent.pop()
verticies.forEach(vert => {
if (name === vert.name && vert.distance === null) {
nodes.push(vert)
}
})
}
return nodes
}`
Please note the only difference being .reverse() on the last line.
lines 41-43 have comments as follow:
// but these nodes are not in the node list? // 23rd&Broadway // 33rd&Lex
23rd&Bwy actually does exist in the vertices array, on line 22.
33rd&Lex does not exist but is not relevant to the previous question.
These comments just add confusion and don't add any clarifying or relevant information.
I found the 'predecessor' properties to be confusing. There wasn't really any explanation of what they are, and they don't appear to have any purpose in the code.
The predecessor seems to be a pointer back the to 'parent' node, and at some iteration of the curriculum it probably made sense, but currently it isn't needed.
I'd be happy to rewrite the lab to remove it if that would be helpful.
the describe line of the #findAdjacent function names it 'findAdjacentNodes' but then the expect line just calls it 'findAdjacent,' so the test fails if you name your function #findAdjacentNodes instead of #findAdjacent. not a huge thing, but causes some initial confusion
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.