Question
JAVA script Problem : count valid postal codes for a given province code * * The countForProvince() function takes a two-character province code, and
JAVA script
Problem : count valid postal codes for a given province code
*
* The countForProvince() function takes a two-character province code, and
* any number of postal codes, some of which may be invalid. It returns the
* total number of postal codes for the province represented by the two-character
* code.
*
* For example:
*
* countForProvince('ON', 'M5W 1E6') returns 1
* countForProvince('ON', 'Y0A 1L0') returns 0
* countForProvince('ON', 'M5W 1E6', 'N0B 1K0') returns 2
* countForProvince('ON', 'M5W 1E6', 'N0B 1K0', 'Y0A 1L0') returns 2
* countForProvince('ON', 'INVALID', '', 'Y0A 1L0') returns 0
*
* Use the toProvince() function you wrote earlier in your answer.
*
* Throw an error if no postal codes are passed, or if any of the postal codes
* is not a string.
*
* @param {string} provinceCode - a two character province code
* @param {string} ...postalCodes - one or more postal code strings
* @returns {number} the total, or 0
******************************************************************************/
function countForProvince(provinceCode, ...postalCodes) {
// Replace this comment with your code...
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
To solve this problem you need to iterate over the postal codes provided check if each postal code b...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started