chore: import upstream snapshot with attribution
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 11:55:53 +08:00
commit dde272c4b8
19405 changed files with 2730632 additions and 0 deletions
@@ -0,0 +1,89 @@
---
id: 56533eb9ac21ba0edf2244e2
title: Caesars Cipher
challengeType: 5
saveSubmissionToDB: true
forumTopicId: 16003
dashedName: caesars-cipher
---
# --description--
One of the simplest and most widely known <dfn>ciphers</dfn> is a <dfn>Caesar cipher</dfn>, also known as a <dfn>shift cipher</dfn>. In a shift cipher the meanings of the letters are shifted by some set amount.
A common modern use is the <a href="https://www.freecodecamp.org/news/how-to-code-the-caesar-cipher-an-introduction-to-basic-encryption-3bf77b4e19f7/" target="_blank" rel="noopener noreferrer nofollow">ROT13</a> cipher, where the values of the letters are shifted by 13 places. Thus `A ↔ N`, `B ↔ O` and so on.
Write a function which takes a <a href="https://www.freecodecamp.org/news/how-to-code-the-caesar-cipher-an-introduction-to-basic-encryption-3bf77b4e19f7/" target="_blank" rel="noopener noreferrer nofollow">ROT13</a> encoded string as input and returns a decoded string.
All letters will be uppercase. Do not transform any non-alphabetic character (i.e. spaces, punctuation), but do pass them on.
# --hints--
`rot13("SERR PBQR PNZC")` should decode to the string `FREE CODE CAMP`
```js
assert(rot13('SERR PBQR PNZC') === 'FREE CODE CAMP');
```
`rot13("SERR CVMMN!")` should decode to the string `FREE PIZZA!`
```js
assert(rot13('SERR CVMMN!') === 'FREE PIZZA!');
```
`rot13("SERR YBIR?")` should decode to the string `FREE LOVE?`
```js
assert(rot13('SERR YBIR?') === 'FREE LOVE?');
```
`rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.")` should decode to the string `THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.`
```js
assert(
rot13('GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.') ===
'THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.'
);
```
# --seed--
## --seed-contents--
```js
function rot13(str) {
return str;
}
rot13("SERR PBQR PNZC");
```
# --solutions--
```js
var lookup = {
'A': 'N','B': 'O','C': 'P','D': 'Q',
'E': 'R','F': 'S','G': 'T','H': 'U',
'I': 'V','J': 'W','K': 'X','L': 'Y',
'M': 'Z','N': 'A','O': 'B','P': 'C',
'Q': 'D','R': 'E','S': 'F','T': 'G',
'U': 'H','V': 'I','W': 'J','X': 'K',
'Y': 'L','Z': 'M'
};
function rot13(encodedStr) {
var codeArr = encodedStr.split(""); // String to Array
var decodedArr = []; // Your Result goes here
// Only change code below this line
decodedArr = codeArr.map(function(letter) {
if(lookup.hasOwnProperty(letter)) {
letter = lookup[letter];
}
return letter;
});
// Only change code above this line
return decodedArr.join(""); // Array to String
}
```
@@ -0,0 +1,216 @@
---
id: a7f4d8f2483413a6ce226cac
title: Roman Numeral Converter
challengeType: 5
saveSubmissionToDB: true
forumTopicId: 16044
dashedName: roman-numeral-converter
---
# --description--
Convert the given number into a roman numeral.
| Roman numerals | Arabic numerals |
|----------------|-----------------|
| M | 1000 |
| CM | 900 |
| D | 500 |
| CD | 400 |
| C | 100 |
| XC | 90 |
| L | 50 |
| XL | 40 |
| X | 10 |
| IX | 9 |
| V | 5 |
| IV | 4 |
| I | 1 |
All roman numerals answers should be provided in upper-case.
# --hints--
`convertToRoman(2)` should return the string `II`.
```js
assert.deepEqual(convertToRoman(2), 'II');
```
`convertToRoman(3)` should return the string `III`.
```js
assert.deepEqual(convertToRoman(3), 'III');
```
`convertToRoman(4)` should return the string `IV`.
```js
assert.deepEqual(convertToRoman(4), 'IV');
```
`convertToRoman(5)` should return the string `V`.
```js
assert.deepEqual(convertToRoman(5), 'V');
```
`convertToRoman(9)` should return the string `IX`.
```js
assert.deepEqual(convertToRoman(9), 'IX');
```
`convertToRoman(12)` should return the string `XII`.
```js
assert.deepEqual(convertToRoman(12), 'XII');
```
`convertToRoman(16)` should return the string `XVI`.
```js
assert.deepEqual(convertToRoman(16), 'XVI');
```
`convertToRoman(29)` should return the string `XXIX`.
```js
assert.deepEqual(convertToRoman(29), 'XXIX');
```
`convertToRoman(44)` should return the string `XLIV`.
```js
assert.deepEqual(convertToRoman(44), 'XLIV');
```
`convertToRoman(45)` should return the string `XLV`.
```js
assert.deepEqual(convertToRoman(45), 'XLV');
```
`convertToRoman(68)` should return the string `LXVIII`
```js
assert.deepEqual(convertToRoman(68), 'LXVIII');
```
`convertToRoman(83)` should return the string `LXXXIII`
```js
assert.deepEqual(convertToRoman(83), 'LXXXIII');
```
`convertToRoman(97)` should return the string `XCVII`
```js
assert.deepEqual(convertToRoman(97), 'XCVII');
```
`convertToRoman(99)` should return the string `XCIX`
```js
assert.deepEqual(convertToRoman(99), 'XCIX');
```
`convertToRoman(400)` should return the string `CD`
```js
assert.deepEqual(convertToRoman(400), 'CD');
```
`convertToRoman(500)` should return the string `D`
```js
assert.deepEqual(convertToRoman(500), 'D');
```
`convertToRoman(501)` should return the string `DI`
```js
assert.deepEqual(convertToRoman(501), 'DI');
```
`convertToRoman(649)` should return the string `DCXLIX`
```js
assert.deepEqual(convertToRoman(649), 'DCXLIX');
```
`convertToRoman(798)` should return the string `DCCXCVIII`
```js
assert.deepEqual(convertToRoman(798), 'DCCXCVIII');
```
`convertToRoman(891)` should return the string `DCCCXCI`
```js
assert.deepEqual(convertToRoman(891), 'DCCCXCI');
```
`convertToRoman(1000)` should return the string `M`
```js
assert.deepEqual(convertToRoman(1000), 'M');
```
`convertToRoman(1004)` should return the string `MIV`
```js
assert.deepEqual(convertToRoman(1004), 'MIV');
```
`convertToRoman(1006)` should return the string `MVI`
```js
assert.deepEqual(convertToRoman(1006), 'MVI');
```
`convertToRoman(1023)` should return the string `MXXIII`
```js
assert.deepEqual(convertToRoman(1023), 'MXXIII');
```
`convertToRoman(2014)` should return the string `MMXIV`
```js
assert.deepEqual(convertToRoman(2014), 'MMXIV');
```
`convertToRoman(3999)` should return the string `MMMCMXCIX`
```js
assert.deepEqual(convertToRoman(3999), 'MMMCMXCIX');
```
# --seed--
## --seed-contents--
```js
function convertToRoman(num) {
return num;
}
convertToRoman(36);
```
# --solutions--
```js
function convertToRoman(num) {
var ref = [['M', 1000], ['CM', 900], ['D', 500], ['CD', 400], ['C', 100], ['XC', 90], ['L', 50], ['XL', 40], ['X', 10], ['IX', 9], ['V', 5], ['IV', 4], ['I', 1]];
var res = [];
ref.forEach(function(p) {
while (num >= p[1]) {
res.push(p[0]);
num -= p[1];
}
});
return res.join('');
}
```
@@ -0,0 +1,253 @@
---
id: aa2e6f85cab2ab736c9a9b24
title: Cash Register
challengeType: 5
saveSubmissionToDB: true
forumTopicId: 16012
dashedName: cash-register
---
# --description--
Design a cash register drawer function `checkCashRegister()` that accepts purchase price as the first argument (`price`), payment as the second argument (`cash`), and cash-in-drawer (`cid`) as the third argument.
`cid` is a 2D array listing available currency.
The `checkCashRegister()` function should always return an object with a `status` key and a `change` key.
Return `{status: "INSUFFICIENT_FUNDS", change: []}` if cash-in-drawer is less than the change due, or if you cannot return the exact change.
Return `{status: "CLOSED", change: [...]}` with cash-in-drawer as the value for the key `change` if it is equal to the change due.
Otherwise, return `{status: "OPEN", change: [...]}`, with the change due in coins and bills, sorted in highest to lowest order, as the value of the `change` key.
<table><tbody><tr><th>Currency Unit</th><th>Amount</th></tr><tr><td>Penny</td><td>$0.01 (PENNY)</td></tr><tr><td>Nickel</td><td>$0.05 (NICKEL)</td></tr><tr><td>Dime</td><td>$0.1 (DIME)</td></tr><tr><td>Quarter</td><td>$0.25 (QUARTER)</td></tr><tr><td>Dollar</td><td>$1 (ONE)</td></tr><tr><td>Five Dollars</td><td>$5 (FIVE)</td></tr><tr><td>Ten Dollars</td><td>$10 (TEN)</td></tr><tr><td>Twenty Dollars</td><td>$20 (TWENTY)</td></tr><tr><td>One-hundred Dollars</td><td>$100 (ONE HUNDRED)</td></tr></tbody></table>
See below for an example of a cash-in-drawer array:
```js
[
["PENNY", 1.01],
["NICKEL", 2.05],
["DIME", 3.1],
["QUARTER", 4.25],
["ONE", 90],
["FIVE", 55],
["TEN", 20],
["TWENTY", 60],
["ONE HUNDRED", 100]
]
```
# --hints--
`checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])` should return an object.
```js
assert.deepEqual(
Object.prototype.toString.call(
checkCashRegister(19.5, 20, [
['PENNY', 1.01],
['NICKEL', 2.05],
['DIME', 3.1],
['QUARTER', 4.25],
['ONE', 90],
['FIVE', 55],
['TEN', 20],
['TWENTY', 60],
['ONE HUNDRED', 100]
])
),
'[object Object]'
);
```
`checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])` should return `{status: "OPEN", change: [["QUARTER", 0.5]]}`.
```js
assert.deepEqual(
checkCashRegister(19.5, 20, [
['PENNY', 1.01],
['NICKEL', 2.05],
['DIME', 3.1],
['QUARTER', 4.25],
['ONE', 90],
['FIVE', 55],
['TEN', 20],
['TWENTY', 60],
['ONE HUNDRED', 100]
]),
{ status: 'OPEN', change: [['QUARTER', 0.5]] }
);
```
`checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])` should return `{status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]}`.
```js
assert.deepEqual(
checkCashRegister(3.26, 100, [
['PENNY', 1.01],
['NICKEL', 2.05],
['DIME', 3.1],
['QUARTER', 4.25],
['ONE', 90],
['FIVE', 55],
['TEN', 20],
['TWENTY', 60],
['ONE HUNDRED', 100]
]),
{
status: 'OPEN',
change: [
['TWENTY', 60],
['TEN', 20],
['FIVE', 15],
['ONE', 1],
['QUARTER', 0.5],
['DIME', 0.2],
['PENNY', 0.04]
]
}
);
```
`checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])` should return `{status: "INSUFFICIENT_FUNDS", change: []}`.
```js
assert.deepEqual(
checkCashRegister(19.5, 20, [
['PENNY', 0.01],
['NICKEL', 0],
['DIME', 0],
['QUARTER', 0],
['ONE', 0],
['FIVE', 0],
['TEN', 0],
['TWENTY', 0],
['ONE HUNDRED', 0]
]),
{ status: 'INSUFFICIENT_FUNDS', change: [] }
);
```
`checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])` should return `{status: "INSUFFICIENT_FUNDS", change: []}`.
```js
assert.deepEqual(
checkCashRegister(19.5, 20, [
['PENNY', 0.01],
['NICKEL', 0],
['DIME', 0],
['QUARTER', 0],
['ONE', 1],
['FIVE', 0],
['TEN', 0],
['TWENTY', 0],
['ONE HUNDRED', 0]
]),
{ status: 'INSUFFICIENT_FUNDS', change: [] }
);
```
`checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])` should return `{status: "CLOSED", change: [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]}`.
```js
assert.deepEqual(
checkCashRegister(19.5, 20, [
['PENNY', 0.5],
['NICKEL', 0],
['DIME', 0],
['QUARTER', 0],
['ONE', 0],
['FIVE', 0],
['TEN', 0],
['TWENTY', 0],
['ONE HUNDRED', 0]
]),
{
status: 'CLOSED',
change: [
['PENNY', 0.5],
['NICKEL', 0],
['DIME', 0],
['QUARTER', 0],
['ONE', 0],
['FIVE', 0],
['TEN', 0],
['TWENTY', 0],
['ONE HUNDRED', 0]
]
}
);
```
# --seed--
## --seed-contents--
```js
function checkCashRegister(price, cash, cid) {
let change;
return change;
}
checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
```
# --solutions--
```js
const denom = [
{ name: "ONE HUNDRED", val: 100 },
{ name: "TWENTY", val: 20 },
{ name: "TEN", val: 10 },
{ name: "FIVE", val: 5 },
{ name: "ONE", val: 1 },
{ name: "QUARTER", val: 0.25 },
{ name: "DIME", val: 0.1 },
{ name: "NICKEL", val: 0.05 },
{ name: "PENNY", val: 0.01 },
];
function checkCashRegister(price, cash, cid) {
const output = { status: null, change: [] };
let change = cash - price;
const register = cid.reduce(
function (acc, curr) {
acc.total += curr[1];
acc[curr[0]] = curr[1];
return acc;
},
{ total: 0 }
);
if (register.total === change) {
output.status = "CLOSED";
output.change = cid;
return output;
}
if (register.total < change) {
output.status = "INSUFFICIENT_FUNDS";
return output;
}
const change_arr = denom.reduce(function (acc, curr) {
let value = 0;
while (register[curr.name] > 0 && change >= curr.val) {
change -= curr.val;
register[curr.name] -= curr.val;
value += curr.val;
change = Math.round(change * 100) / 100;
}
if (value > 0) {
acc.push([curr.name, value]);
}
return acc;
}, []);
if (change_arr.length < 1 || change > 0) {
output.status = "INSUFFICIENT_FUNDS";
return output;
}
output.status = "OPEN";
output.change = change_arr;
return output;
}
```
@@ -0,0 +1,126 @@
---
id: aaa48de84e1ecc7c742e1124
title: Palindrome Checker
challengeType: 5
saveSubmissionToDB: true
forumTopicId: 16004
dashedName: palindrome-checker
---
# --description--
Return `true` if the given string is a palindrome. Otherwise, return `false`.
A <dfn>palindrome</dfn> is a word or sentence that's spelled the same way both forward and backward, ignoring punctuation, case, and spacing.
**Note:** You'll need to remove **all non-alphanumeric characters** (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.
We'll pass strings with varying formats, such as `racecar`, `RaceCar`, and `race CAR` among others.
We'll also pass strings with special symbols, such as `2A3*3a2`, `2A3 3a2`, and `2_A3*3#A2`.
# --hints--
`palindrome("eye")` should return a boolean.
```js
assert(typeof palindrome('eye') === 'boolean');
```
`palindrome("eye")` should return `true`.
```js
assert(palindrome('eye') === true);
```
`palindrome("_eye")` should return `true`.
```js
assert(palindrome('_eye') === true);
```
`palindrome("race car")` should return `true`.
```js
assert(palindrome('race car') === true);
```
`palindrome("not a palindrome")` should return `false`.
```js
assert(palindrome('not a palindrome') === false);
```
`palindrome("A man, a plan, a canal. Panama")` should return `true`.
```js
assert(palindrome('A man, a plan, a canal. Panama') === true);
```
`palindrome("never odd or even")` should return `true`.
```js
assert(palindrome('never odd or even') === true);
```
`palindrome("nope")` should return `false`.
```js
assert(palindrome('nope') === false);
```
`palindrome("almostomla")` should return `false`.
```js
assert(palindrome('almostomla') === false);
```
`palindrome("My age is 0, 0 si ega ym.")` should return `true`.
```js
assert(palindrome('My age is 0, 0 si ega ym.') === true);
```
`palindrome("1 eye for of 1 eye.")` should return `false`.
```js
assert(palindrome('1 eye for of 1 eye.') === false);
```
`palindrome("0_0 (: /-\ :) 0-0")` should return `true`.
```js
assert(palindrome('0_0 (: /- :) 0-0') === true);
```
`palindrome("five|\_/|four")` should return `false`.
```js
assert(palindrome('five|_/|four') === false);
```
# --seed--
## --seed-contents--
```js
function palindrome(str) {
return true;
}
palindrome("eye");
```
# --solutions--
```js
function palindrome(str) {
var string = str.toLowerCase().split(/[^A-Za-z0-9]/gi).join('');
var aux = string.split('');
if (aux.join('') === aux.reverse().join('')){
return true;
}
return false;
}
```
@@ -0,0 +1,264 @@
---
id: aff0395860f5d3034dc0bfc9
title: Telephone Number Validator
challengeType: 5
saveSubmissionToDB: true
forumTopicId: 16090
dashedName: telephone-number-validator
---
# --description--
Return `true` if the passed string looks like a valid US phone number.
The user may fill out the form field any way they choose as long as it has the format of a valid US number. The following are examples of valid formats for US numbers (refer to the tests below for other variants):
<blockquote>555-555-5555<br>(555)555-5555<br>(555) 555-5555<br>555 555 5555<br>5555555555<br>1 555 555 5555</blockquote>
For this challenge you will be presented with a string such as `800-692-7753` or `8oo-six427676;laskdjf`. Your job is to validate or reject the US phone number based on any combination of the formats provided above. The area code is required. If the country code is provided, you must confirm that the country code is `1`. Return `true` if the string is a valid US phone number; otherwise return `false`.
# --hints--
`telephoneCheck("555-555-5555")` should return a boolean.
```js
assert(typeof telephoneCheck('555-555-5555') === 'boolean');
```
`telephoneCheck("1 555-555-5555")` should return `true`.
```js
assert(telephoneCheck('1 555-555-5555') === true);
```
`telephoneCheck("1 (555) 555-5555")` should return `true`.
```js
assert(telephoneCheck('1 (555) 555-5555') === true);
```
`telephoneCheck("5555555555")` should return `true`.
```js
assert(telephoneCheck('5555555555') === true);
```
`telephoneCheck("555-555-5555")` should return `true`.
```js
assert(telephoneCheck('555-555-5555') === true);
```
`telephoneCheck("(555)555-5555")` should return `true`.
```js
assert(telephoneCheck('(555)555-5555') === true);
```
`telephoneCheck("1(555)555-5555")` should return `true`.
```js
assert(telephoneCheck('1(555)555-5555') === true);
```
`telephoneCheck("555-5555")` should return `false`.
```js
assert(telephoneCheck('555-5555') === false);
```
`telephoneCheck("5555555")` should return `false`.
```js
assert(telephoneCheck('5555555') === false);
```
`telephoneCheck("1 555)555-5555")` should return `false`.
```js
assert(telephoneCheck('1 555)555-5555') === false);
```
`telephoneCheck("1 555 555 5555")` should return `true`.
```js
assert(telephoneCheck('1 555 555 5555') === true);
```
`telephoneCheck("1 456 789 4444")` should return `true`.
```js
assert(telephoneCheck('1 456 789 4444') === true);
```
`telephoneCheck("123**&!!asdf#")` should return `false`.
```js
assert(telephoneCheck('123**&!!asdf#') === false);
```
`telephoneCheck("55555555")` should return `false`.
```js
assert(telephoneCheck('55555555') === false);
```
`telephoneCheck("(6054756961)")` should return `false`.
```js
assert(telephoneCheck('(6054756961)') === false);
```
`telephoneCheck("2 (757) 622-7382")` should return `false`.
```js
assert(telephoneCheck('2 (757) 622-7382') === false);
```
`telephoneCheck("0 (757) 622-7382")` should return `false`.
```js
assert(telephoneCheck('0 (757) 622-7382') === false);
```
`telephoneCheck("-1 (757) 622-7382")` should return `false`.
```js
assert(telephoneCheck('-1 (757) 622-7382') === false);
```
`telephoneCheck("2 757 622-7382")` should return `false`.
```js
assert(telephoneCheck('2 757 622-7382') === false);
```
`telephoneCheck("10 (757) 622-7382")` should return `false`.
```js
assert(telephoneCheck('10 (757) 622-7382') === false);
```
`telephoneCheck("27576227382")` should return `false`.
```js
assert(telephoneCheck('27576227382') === false);
```
`telephoneCheck("(275)76227382")` should return `false`.
```js
assert(telephoneCheck('(275)76227382') === false);
```
`telephoneCheck("2(757)6227382")` should return `false`.
```js
assert(telephoneCheck('2(757)6227382') === false);
```
`telephoneCheck("2(757)622-7382")` should return `false`.
```js
assert(telephoneCheck('2(757)622-7382') === false);
```
`telephoneCheck("555)-555-5555")` should return `false`.
```js
assert(telephoneCheck('555)-555-5555') === false);
```
`telephoneCheck("(555-555-5555")` should return `false`.
```js
assert(telephoneCheck('(555-555-5555') === false);
```
`telephoneCheck("(555)5(55?)-5555")` should return `false`.
```js
assert(telephoneCheck('(555)5(55?)-5555') === false);
```
`telephoneCheck("55 55-55-555-5")` should return `false`.
```js
assert(telephoneCheck('55 55-55-555-5') === false);
```
`telephoneCheck("11 555-555-5555")` should return `false`.
```js
assert(telephoneCheck('11 555-555-5555') === false);
```
`telephoneCheck()`, when called with any valid number, should return `true`.
```js
const validPatterns = [
'1 XXX-XXX-XXXX',
'1 (XXX) XXX-XXXX',
'1(XXX)XXX-XXXX',
'1 XXX XXX XXXX',
'XXXXXXXXXX',
'XXX-XXX-XXXX',
'(XXX)XXX-XXXX',
];
validPatterns.forEach(pattern => {
while (pattern.includes('X')) {
pattern = pattern.replace('X', Math.floor(Math.random() * 7) + 2); //While this may seem weird at first, it's required for the CI build to pass
//This is apparently because the solution provided for CI purposes actually checks for valid area and exchange codes.
}
assert.isTrue(telephoneCheck(pattern));
});
```
`telephoneCheck()`, when called with an invalid number, should return `false`.
```js
const invalidPatterns = [
'10 XXX-XXX-XXXX',
'1 (XX)XXX-XXXX',
'1!(XXX)XXX-XXXX',
'-1 XXX XXX XXXX',
'XXXXXXXX',
'XXX#XXX-XXXX',
'(XXXXXX-XXXX',
];
invalidPatterns.forEach(pattern => {
while (pattern.includes('X')) {
pattern = pattern.replace('X', Math.floor(Math.random() * 10));
}
assert.isFalse(telephoneCheck(pattern));
});
```
# --seed--
## --seed-contents--
```js
function telephoneCheck(str) {
return true;
}
telephoneCheck("555-555-5555");
```
# --solutions--
```js
var re = /^([+]?1[\s]?)?((?:[(](?:[2-9]1[02-9]|[2-9][02-8][0-9])[)][\s]?)|(?:(?:[2-9]1[02-9]|[2-9][02-8][0-9])[\s.-]?)){1}([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2}[\s.-]?){1}([0-9]{4}){1}$/;
function telephoneCheck(str) {
return re.test(str);
}
telephoneCheck("555-555-5555");
```