Fixed formatting problems, added JSDoc, added example for JS, fixed example for JS

This commit is contained in:
Alexandrshy
2019-07-24 22:38:14 +04:00
parent bac32b613b
commit b4b5161ff9
4 changed files with 108 additions and 29 deletions

View File

@@ -1,18 +1,27 @@
const personIsSeller = name => name[name.length - 1] === 'm';
const graph = {};
graph.you = ['alice', 'bob', 'claire'];
graph.bob = ['anuj', 'peggy'];
graph.alice = ['peggy'];
graph.claire = ['thom', 'jonny'];
graph.you = ["alice", "bob", "claire"];
graph.bob = ["anuj", "peggy"];
graph.alice = ["peggy"];
graph.claire = ["thom", "jonny"];
graph.anuj = [];
graph.peggy = [];
graph.thom = [];
graph.jonny = [];
const search = (name) => {
let searchQueue = [];
searchQueue = searchQueue.concat(graph[name]);
/**
* Determine whether a person is a seller
* @param {string} name Friend's name
* @returns {boolean} Result of checking
*/
const personIsSeller = name => name[name.length - 1] === "m";
/**
* Find a mango seller
* @param {string} name Friend's name
* @returns {boolean} Search results
*/
const search = name => {
let searchQueue = [...graph[name]];
// This array is how you keep track of which people you've searched before.
const searched = [];
while (searchQueue.length) {
@@ -31,4 +40,4 @@ const search = (name) => {
return false;
};
search('you'); // thom is a mango seller!
search("you"); // thom is a mango seller!