Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit feed510

Browse files
committed
Add a question
1 parent 56a1e67 commit feed510

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

‎README.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ const generateHashtag = str => {
15611561

15621562
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
15631563

1564-
## 47. Pete, the baker
1564+
## 47. Pete, the Baker
15651565

15661566
Pete likes to bake some cakes. He has some recipes and ingredients. Unfortunately he is not good in maths. Can you help him to find out, how many cakes he could bake considering his recipes?
15671567

@@ -1604,7 +1604,7 @@ const cakes = (recipe, available) => {
16041604

16051605
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
16061606

1607-
## 48. Count characters in your string
1607+
## 48. Count Characters in Your String
16081608

16091609
Write a function that counts the frequency of all the characters in a given string.
16101610

@@ -1664,7 +1664,7 @@ const solution = str => {
16641664

16651665
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
16661666

1667-
## 50. Check if Word Equals Summation of Two Words
1667+
## 50. Check if Word Equals Summation of Two Words
16681668

16691669
Let's assume that the numeric value of a letter is its position in the alphabet starting from `0` (i.e. `a -> 0, b -> 1, c -> 2`, etc.). Similarly, the numerical value of a string `str` consisting of some lowercase English letters is the concatenation (not sum!) of the numeric values of each letter in `str`, which is then converted into an integer. For example, if `str = 'acb'`, we concatenate each letter's numeric value, resulting in `021` which is then converted to integer `21`.
16701670

@@ -1675,19 +1675,19 @@ const isSumEqual = (firstWord, secondWord, targetWord) => {
16751675
// Your solution
16761676
};
16771677

1678-
console.log(isSumEqual('acb', 'cba', 'cdb'));
1678+
console.log(isSumEqual('acb', 'cba', 'cdb'));// true
16791679
// The numerical value of firstWord 'acb' is '021' -> 21
16801680
// The numerical value of secondWord 'cba' is '210' -> 210
16811681
// The numerical value of targetWord 'cdb' is '231' -> 231
16821682
// So we return true because 21 + 210 == 231
16831683

1684-
console.log(isSumEqual('aaa', 'a', 'aab'));
1684+
console.log(isSumEqual('aaa', 'a', 'aab'));// false
16851685
// The numerical value of firstWord 'aaa' is '000' -> 0
16861686
// The numerical value of secondWord 'a' is '0' -> 0
16871687
// The numerical value of targetWord 'aab' is '001' -> 1
16881688
// So we return false because 0 + 0 != 1
16891689

1690-
console.log(isSumEqual('aaa', 'a', 'aaaa'));
1690+
console.log(isSumEqual('aaa', 'a', 'aaaa'));// true
16911691
// The numerical value of firstWord 'aaa' is '000' -> 0
16921692
// The numerical value of secondWord 'a' is '0' -> 0
16931693
// The numerical value of targetWord 'aaaa' is '0000' -> 0
@@ -1718,3 +1718,36 @@ const isSumEqual = (firstWord, secondWord, targetWord) => {
17181718
---
17191719

17201720
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**
1721+
1722+
## 51. Extract the Domain Name From a URL
1723+
1724+
Write a function that given an input URL, returns its domain name.
1725+
1726+
```js
1727+
const domainName = url => {
1728+
// Your solution
1729+
}
1730+
1731+
console.log(domainName('www.google.ca')); // google
1732+
console.log(domainName('http://google.com')); // google
1733+
console.log(domainName('https://google.com')); // google
1734+
console.log(domainName('http://google.co.jp')); // google
1735+
console.log(domainName('https://www.google.com')); // google
1736+
```
1737+
1738+
<details><summary>Solution</summary>
1739+
1740+
```js
1741+
const domainName = url => {
1742+
return url.replace(/(www\.|.*\/\/|\..+)/g, '');
1743+
}
1744+
1745+
// Alternative solution with no regex
1746+
// const domainName = url => url.replace('http://', '').replace('https://', '').replace('www.', '').split('.')[0];
1747+
```
1748+
1749+
</details>
1750+
1751+
---
1752+
1753+
**[⬆ Back to Top](#javascript-coding-challenges-for-beginners)**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /