Complete "longest common ..." examples (#100)
* no else return * fix var ref * fix importing/requiring dependencies * complete longest common examples
This commit is contained in:
committed by
Aditya Bhargava
parent
c23ca90b83
commit
5b675cc2e8
@@ -1,7 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
function person_is_seller(name) {
|
||||
return name[name.length-1] === 'm';
|
||||
return name[name.length - 1] === "m";
|
||||
}
|
||||
|
||||
const graph = {};
|
||||
@@ -14,7 +12,6 @@ graph["peggy"] = [];
|
||||
graph["thom"] = [];
|
||||
graph["jonny"] = [];
|
||||
|
||||
|
||||
function search(name) {
|
||||
let search_queue = [];
|
||||
search_queue = search_queue.concat(graph[name]);
|
||||
@@ -25,17 +22,16 @@ function search(name) {
|
||||
// Only search this person if you haven't already searched them
|
||||
if (searched.indexOf(person) === -1) {
|
||||
if (person_is_seller(person)) {
|
||||
console.log(person + ' is a mango seller!');
|
||||
console.log(person + " is a mango seller!");
|
||||
return true;
|
||||
} else {
|
||||
search_queue = search_queue.concat(graph[person]);
|
||||
// Marks this person as searched
|
||||
searched.push(person);
|
||||
}
|
||||
|
||||
search_queue = search_queue.concat(graph[person]);
|
||||
// Marks this person as searched
|
||||
searched.push(person);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
search('you'); // thom is a mango seller!
|
||||
search("you"); // thom is a mango seller!
|
||||
|
||||
Reference in New Issue
Block a user