Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ <h3 class="modal-title" id="helpModalLabel">Getting Started</h3>
>Use partial matches to single out stations</strong
>
in a pileup. E.g., for W6NYC, all of the following will
get a reply back: 'W?', 'W6?', 'W6NC', 'NYC'.<br /><br /><i
get a reply back: 'W?', 'W6?', 'W6NC', 'NYC', '6?'.<br /><br /><i
>Note that more than one station may reply if they
match your partial pattern!</i
>
Expand Down
59 changes: 59 additions & 0 deletions src/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export function compareStrings(source, query) {
// console.log("Partial: Criterion 5");
return 'partial';
}
// Check Criterion 6 (Single Number Matches Call Region)
if (criterion6(source, query)) {
// console.log("Partial: Criterion 6");
return 'partial';
}
// If none of the criteria are met
// console.log("None");
return 'none';
Expand Down Expand Up @@ -224,6 +229,47 @@ export function compareStrings(source, query) {

return true;
}

/**
* Criterion 6: Single Number Matches Call Region
*
* - **Conditions:**
* - The query must be a single digit character
* - The callsign must have only a single number
* - They must match
*
* - **Examples:**
* - Source: "AB6ZZ", Query: "6"
* => "AB6ZZ" contains one number, "6".
* => "6" is a single digit
* => "6" matches "6"
*
* @param {string} source
* @param {string} query
* @returns boolean
*/
function criterion6(source, query) {
// The query must be a single digit character
if (!isdigit(query)) {
return false;
}

// The source must contain exactly one digit
let digits = 0;
let source_digit;
for (const ch of source) {
if (isdigit(ch)) {
digits++;
source_digit = ch;
}
}
if (digits != 1) {
return false;
}

// They must match
return source_digit === query;
}
}

// function runCompareStringTestCase(source, query, expectedResult) {
Expand Down Expand Up @@ -650,3 +696,16 @@ function updateSummaryRow(tableName, extra = null) {
export function updateActiveStations(numStations) {
document.getElementById('activeStations').textContent = numStations;
}

/**
* Checks if provided string is a single digit character
*
* @param {string} ch - The prospective digit
* @returns {boolean}
*/
export function isdigit(ch) {
if (ch.length !== 1) {
return false;
}
return '1234567890'.includes(ch);
}