Dear candidate,
First things first, we would like to thank you for taking the time to work on this skill-evaluation
exercise.
The objective of this exercise is to give us a peek into your software modeling and development
skills, as well as your attention to details and quality. As the saying goes:
"
Professionalism is not the job you do, it's how you do the job.
"
The task:
Your team has been tasked with implementing a nodejs function that validates a user’s (Israeli)
ID number.
A valid ID number consists of 9 digits and adheres to the Luhn algorithm
(Search for it on Wiki)
The following code was implemented by your peer:
function isValidTaxId(taxId?: string): boolean {
if (isEmpty(taxId))
return false;
length = taxId.length;
var isValid = false;
if (length == 9) {
var aggr = 0;
for (var i = 0; i < length; i++) {
var char = taxId.substr(i, 1);
var mul = (1 + (i % 2)) * parseInt(char);
if (mul >= 9) {
mul -= 9;
}
aggr += mul;
}
isValid = (aggr % 10 == 0);
}
return isValid;
}
function isEmpty(text?: string): boolean {
return text === null || typeof text === 'undefined' || text.length === 0 || (typeof text ===
'string' && text.trim() === '');
}
Your tasks are as follows:
1. Review your peer’s code and provide your feedback
2. In case you’ve spotted any bugs in the implementation, please point them out and fix
3. Valid Greek ID numbers too, adhere to Luhn algorithm but they consist of exactly 10
digits. Extend the code to support the validation of both Israeli and Greek ID numbers
based on the user’s locale.
4. Valid Bulgarian ID numbers too, adhere to Luhn algorithm but they consist of exactly 8 digits
and the sum of the first two digits must be an odd number. Extend the code to support
Bulgarian ID numbers.
5. How would you unit test the code? Please specify the tests you would implement.
Thank you!