diff --git a/12_Day_Regular_expressions/12_day_regular_expressions.md b/12_Day_Regular_expressions/12_day_regular_expressions.md index 99d85f0..94e132f 100644 --- a/12_Day_Regular_expressions/12_day_regular_expressions.md +++ b/12_Day_Regular_expressions/12_day_regular_expressions.md @@ -348,7 +348,7 @@ Zero or many times. The pattern could may not occur or it can occur many times. ```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 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] distance = 12 ``` - 1. Write a pattern which identify if a string is a valid JavaScript variable - ```sh - is_valid_variable('first_name') # True - is_valid_variable('first-name') # False - is_valid_variable('1first_name') # False - is_valid_variable('firstname') # True - ``` +```sh +is_valid_variable('first_name') # True +is_valid_variable('first-name') # False +is_valid_variable('1first_name') # False +is_valid_variable('firstname') # True +``` ### Exercises: Level 2 1. Write a function called *tenMostFrequentWords* which get the ten most frequent word from a string? - ```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.` - console.log(tenMostFrequentWords(paragraph)) - ``` - - ```sh - [ - {word:'love', count:6}, - {word:'you', count:5}, - {word:'can', count:3}, - {word:'what', count:2}, - {word:'teaching', count:2}, - {word:'not', count:2}, - {word:'else', count:2}, - {word:'do', count:2}, - {word:'I', count:2}, - {word:'which', count:1}, - {word:'to', count:1}, - {word:'the', count:1}, - {word:'something', count:1}, - {word:'if', count:1}, - {word:'give', count:1}, - {word:'develop',count:1}, - {word:'capabilities',count:1}, - {word:'application', count:1}, - {word:'an',count:1}, - {word:'all',count:1}, - {word:'Python',count:1}, - {word:'If',count:1}] - ``` - - ```js - console.log(tenMostFrequentWords(paragraph, 10)) - ``` - - ```sh - [{word:'love', count:6}, - {word:'you', count:5}, - {word:'can', count:3}, - {word:'what', count:2}, - {word:'teaching', count:2}, - {word:'not', count:2}, - {word:'else', count:2}, - {word:'do', count:2}, - {word:'I', count:2}, - {word:'which', count:1} - ] - ``` +```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.` +console.log(tenMostFrequentWords(paragraph)) +``` + +```sh +[ +{word:'love', count:6}, +{word:'you', count:5}, +{word:'can', count:3}, +{word:'what', count:2}, +{word:'teaching', count:2}, +{word:'not', count:2}, +{word:'else', count:2}, +{word:'do', count:2}, +{word:'I', count:2}, +{word:'which', count:1}, +{word:'to', count:1}, +{word:'the', count:1}, +{word:'something', count:1}, +{word:'if', count:1}, +{word:'give', count:1}, +{word:'develop',count:1}, +{word:'capabilities',count:1}, +{word:'application', count:1}, +{word:'an',count:1}, +{word:'all',count:1}, +{word:'Python',count:1}, +{word:'If',count:1}] +``` + +```js +console.log(tenMostFrequentWords(paragraph, 10)) +``` + +```sh +[ +{word:'love', count:6}, +{word:'you', count:5}, +{word:'can', count:3}, +{word:'what', count:2}, +{word:'teaching', count:2}, +{word:'not', count:2}, +{word:'else', count:2}, +{word:'do', count:2}, +{word:'I', count:2}, +{word:'which', count:1} +] +``` ### 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 - 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!?` +```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!?` - console.log(cleanText(sentence)) - ``` +console.log(cleanText(sentence)) +``` - ```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 - ``` +```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 +``` 1. Write a function which find the most frequent words. After cleaning, count three most frequent words in the string. - ```js - console.log(mostFrequentWords(cleanedText)) - [{word:'I', count:3}, {word:'teaching', count:2}, {word:'teacher', count:2}] - ``` +```js +console.log(mostFrequentWords(cleanedText)) +``` +```sh +[{word:'I', count:3}, {word:'teaching', count:2}, {word:'teacher', count:2}] +``` 🎉 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) \ No newline at end of file