Tell us what’s happening:
Step 5 is not being validated.
I’ve tried several different ways.
I don’t know where I’m going wrong.
Your code so far
const adjacencyListToMatrix = (list) => {
const nodes = Object.keys(list);
const n = nodes.length;
const matrix = Array.from({ length: n }, () => Array(n).fill(0));
for (const node in list) {
const neighbors = list[node];
neighbors.forEach(neighbor => {
matrix[node][neighbor] = 1;
})
}
const rowsFormatted = matrix.map(row => `[${row.join(", ")}]`).join(", ");
const finalOutput = `[${rowsFormatted}]`;
console.log(finalOutput);
return matrix;
}
adjacencyListToMatrix({0: [1, 2], 1: [2], 2: [0, 3], 3: [2]})
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:149.0) Gecko/20100101 Firefox/149.0
Challenge Information:
Build an Adjacency List to Matrix Converter - Build an Adjacency List to Matrix Converter