CS2613/labs/L09/ancestry.js

12 lines
510 B
JavaScript
Raw Permalink Normal View History

2022-10-12 11:10:43 -03:00
let read_json_file = require("./read_json_file.js").read_json_file;
let data = null;
function by_name(name) {
if (data === null)
data = read_json_file("./ancestry.json");
// simple linear scan
result = data.find(person => person.name === name) // find the result of the first person with the name
return (result === undefined) ? null : result; // if the result is undefined, return null, otherwise return the result (since tests expect null not undefined)
}
exports.by_name = by_name;