fix some error in day 12

pull/113/head
Kamrul Islam Shahin 5 years ago
parent d6fbf69b66
commit 7985dc1b9d

@ -348,7 +348,7 @@ Zero or many times. The pattern could may not occur or it can occur many times.
```js ```js
const pattern = /[a].*/g //. any character, + any character one or more times const pattern = /[a].*/g //. any character, * any character zero or more times
const txt = 'Apple and banana are fruits' const txt = 'Apple and banana are fruits'
const matches = txt.match(pattern) const matches = txt.match(pattern)
@ -434,91 +434,92 @@ points = ['-1', '2', '-4', '-3', '-1', '0', '4', '8']
sortedPoints = [-4, -3, -1, -1, 0, 2, 4, 8] sortedPoints = [-4, -3, -1, -1, 0, 2, 4, 8]
distance = 12 distance = 12
``` ```
1. Write a pattern which identify if a string is a valid JavaScript variable 1. Write a pattern which identify if a string is a valid JavaScript variable
```sh ```sh
is_valid_variable('first_name') # True is_valid_variable('first_name') # True
is_valid_variable('first-name') # False is_valid_variable('first-name') # False
is_valid_variable('1first_name') # False is_valid_variable('1first_name') # False
is_valid_variable('firstname') # True is_valid_variable('firstname') # True
``` ```
### Exercises: Level 2 ### Exercises: Level 2
1. Write a function called *tenMostFrequentWords* which get the ten most frequent word from a string? 1. Write a function called *tenMostFrequentWords* which get the ten most frequent word from a string?
```js ```js
paragraph = `I love teaching. If you do not love teaching what else can you love. I love Python if you do not love something which can give you all the capabilities to develop an application what else can you love.` paragraph = `I love teaching. If you do not love teaching what else can you love. I love Python if you do not love something which can give you all the capabilities to develop an application what else can you love.`
console.log(tenMostFrequentWords(paragraph)) console.log(tenMostFrequentWords(paragraph))
``` ```
```sh ```sh
[ [
{word:'love', count:6}, {word:'love', count:6},
{word:'you', count:5}, {word:'you', count:5},
{word:'can', count:3}, {word:'can', count:3},
{word:'what', count:2}, {word:'what', count:2},
{word:'teaching', count:2}, {word:'teaching', count:2},
{word:'not', count:2}, {word:'not', count:2},
{word:'else', count:2}, {word:'else', count:2},
{word:'do', count:2}, {word:'do', count:2},
{word:'I', count:2}, {word:'I', count:2},
{word:'which', count:1}, {word:'which', count:1},
{word:'to', count:1}, {word:'to', count:1},
{word:'the', count:1}, {word:'the', count:1},
{word:'something', count:1}, {word:'something', count:1},
{word:'if', count:1}, {word:'if', count:1},
{word:'give', count:1}, {word:'give', count:1},
{word:'develop',count:1}, {word:'develop',count:1},
{word:'capabilities',count:1}, {word:'capabilities',count:1},
{word:'application', count:1}, {word:'application', count:1},
{word:'an',count:1}, {word:'an',count:1},
{word:'all',count:1}, {word:'all',count:1},
{word:'Python',count:1}, {word:'Python',count:1},
{word:'If',count:1}] {word:'If',count:1}]
``` ```
```js ```js
console.log(tenMostFrequentWords(paragraph, 10)) console.log(tenMostFrequentWords(paragraph, 10))
``` ```
```sh ```sh
[{word:'love', count:6}, [
{word:'you', count:5}, {word:'love', count:6},
{word:'can', count:3}, {word:'you', count:5},
{word:'what', count:2}, {word:'can', count:3},
{word:'teaching', count:2}, {word:'what', count:2},
{word:'not', count:2}, {word:'teaching', count:2},
{word:'else', count:2}, {word:'not', count:2},
{word:'do', count:2}, {word:'else', count:2},
{word:'I', count:2}, {word:'do', count:2},
{word:'which', count:1} {word:'I', count:2},
] {word:'which', count:1}
``` ]
```
### Exercises: Level 3 ### Exercises: Level 3
1. Writ a function which cleans text. Clean the following text. After cleaning, count three most frequent words in the string. 1. Write a function which cleans text. Clean the following text. After cleaning, count three most frequent words in the string.
```js ```js
sentence = `%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& @emp%o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!?` sentence = `%I $am@% a %tea@cher%, &and& I lo%#ve %tea@ching%;. There $is nothing; &as& mo@re rewarding as educa@ting &and& @emp%o@wering peo@ple. ;I found tea@ching m%o@re interesting tha@n any other %jo@bs. %Do@es thi%s mo@tivate yo@u to be a tea@cher!?`
console.log(cleanText(sentence)) console.log(cleanText(sentence))
``` ```
```sh ```sh
I am a teacher and I love teaching There is nothing as more rewarding as educating and empowering people I found teaching more interesting than any other jobs Does this motivate you to be a teacher I am a teacher and I love teaching There is nothing as more rewarding as educating and empowering people I found teaching more interesting than any other jobs Does this motivate you to be a teacher
``` ```
1. Write a function which find the most frequent words. After cleaning, count three most frequent words in the string. 1. Write a function which find the most frequent words. After cleaning, count three most frequent words in the string.
```js ```js
console.log(mostFrequentWords(cleanedText)) console.log(mostFrequentWords(cleanedText))
[{word:'I', count:3}, {word:'teaching', count:2}, {word:'teacher', count:2}] ```
```
```sh
[{word:'I', count:3}, {word:'teaching', count:2}, {word:'teacher', count:2}]
```
🎉 CONGRATULATIONS ! 🎉 🎉 CONGRATULATIONS ! 🎉
[<< Day 11](../11_Day_Destructuring_and_spreading/11_day_destructuring_and_spreading.md) | [Day 13>>](../13_Day_Console_object_methods/13_day_console_object_methods.md) [<< Day 11](../11_Day_Destructuring_and_spreading/11_day_destructuring_and_spreading.md) | [Day 13>>](../13_Day_Console_object_methods/13_day_console_object_methods.md)
Loading…
Cancel
Save