I am joining a new company and I want to make a positive impact in regards to my code.
I was asked to do compare two fuzzy name and return if the name is valid or not.
For this I wrote the following code
import fuzzy from 'fuzzy'
const {driverName, tlcNumber} = input
if (!tlcNumber) {
throw new Error("tlcNumber not specified");
}
if (!driverName) {
throw new Error("Driver Number not specified");
}
const result = await getDriver(input.tlcNumber);
if (!result) {
return {
valid: false,
message: `TLC number ${tlcNumber} is not found in the TLC database`
}
}
const {name:tlcRegisteredName} = result
driverName.split(' ').forEach(name => {
const fuzzyMatch = fuzzy.test(name, tlcRegisteredName)
if (!fuzzyMatch) {
return {
valid: false,
message: `TLC number ${tlcNumber} is registered to ${tlcRegisteredName} which does not match ${driverName}`
}
}
});
return {
valid:true
}
Can someone help me in making this code better? or how I would Improve? I have been told to
separate first and last names and do fuzzy matching independently on each
I am using the fuzzy
library.