Skip to content

Commit 4f313df

Browse files
committed
vowel counter explanation added
1 parent e72bff4 commit 4f313df

File tree

1 file changed

+71
-6
lines changed

1 file changed

+71
-6
lines changed

README.md

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
### This is open-source Project
44
__If you want to contribute then follow theses steps__
55
>1.fork the repo. <br>2.take the algorithm which you want to add to list<br> 3.Make sure it's not repeated. <br> 4. Be ready with your code in *JAVASCRIPT* <br> 5.The added algorithm should have following sub-sections <br>
6-
> 5.1 A short Introduction
7-
5.2 The challenge
8-
5.3 Algorithmic thinking
9-
5.4 Code Implementation
6+
> 5.1 A short Introduction <br>
7+
> 5.2 The challenge<br>
8+
> 5.3 Algorithmic thinking<br>
9+
> 5.4 Code Implementation <br>
1010
1111

1212
__Algorithms practiced using JS__
@@ -87,10 +87,72 @@ We will now explore ways to solve this challenge below. They are:
8787
<hr>
8888
<b>2. Vowel counter </b>
8989

90-
__The challenge:__
90+
<p>Here we will be working with strings and arrays. The main challenge is given in The challenge section below.Let's find it </p>
91+
92+
__The challenge:__ <p>You are given a string of text containing zero or more vowels in it,count the number of vowels that can be found in given text. For example:</p>
93+
94+
```js
95+
vowelCounter("Hacktoberfest is very Nice") //will return 8
96+
```
97+
98+
99+
__Algorithmic Thinking:__ <p> After reading the problem statement, __ given text of string__ must be in your mind. Let's go further to explore</p>
100+
101+
> A function is a block of organized, reusable code that is used to perform a single, related action. They may or may not accepts value as parameter for computational tasks. The values are also called as Arguments.
102+
103+
*Let's Breakdown the approach*
104+
105+
* write a function which receives a parameter called "text". It should be string of any desired length which is to be passed in function as an argument.
106+
107+
* create a counter to count vowels
108+
109+
* Next, we need to scan the string and search for the vowels ('a','e','i','o','u')
110+
111+
* Function will return the number of vowels found. So you have to use __*return*__ function which stops the the function execution and returns a value.
112+
<br>
113+
114+
__Code Implementation:__
115+
<p> We are going to use Two approaches for solving this problem:</p>
116+
117+
1. Using Iterative approach
118+
2. Using Regular Expression
119+
120+
1.Using Iterative approach:
121+
<br>
122+
```js
123+
const vowel = ["a", "e", "i", "o", "u"];
124+
125+
function vowelcnt(text) {
126+
let counter = 0;
127+
128+
//Loop through text to test if each character is a vowel
129+
for (let letter of text.toLowerCase()) {
130+
if (vowel.includes(letter)) {
131+
counter++;
132+
}
133+
}
134+
135+
// Return number of vowels
136+
137+
return counter;
138+
}
139+
140+
console.log(vowelcnt("i love HacktoberFest"))
141+
```
142+
143+
**Breaking-down the steps:**
144+
145+
* Firstly, we declard const vowel which is array of five vowels.
146+
* We declare a function and initialize the counter.
147+
* We make use of For loop to itearte over the given string. Next, we convert the all letters of string to lowercase as we don't want to miss out on uppercase letters.
148+
* In for loop,use if to check if selected letter is included in the array of vowels which we declared earlier. We call *includes()* method on array of vowels to check whether the array includes selected letter or not.
149+
150+
* If the condition is true, we increment the counter.
151+
* After looping through, counter is returned which gives the counte of vowels found in given string.
152+
153+
91154

92155

93-
__Algorithmic Thinking:__ <p> </p>
94156

95157

96158
<hr>
@@ -106,10 +168,13 @@ maxRecurringChar('aabacada') // will return 'a'
106168
```
107169

108170
__Algorithmic Thinking:__ <p> From the challenge statement, we can infer that our function has only one parameter; the string of text.<br> We need to somehow keep track of every character in the string as well as the number of times it exists. <br> This we would describe as character mapping. Once we successfully create such a map, we can easily determine which character has the highest occurence. </p>
171+
<br>
109172

173+
__Code Implementation:__
110174

111175
<hr>
112176
<hr>
177+
113178
<b>4. Sentence Capitalization</b>
114179
<p> Often during presentation situation arises where we need to manipulate the letter casing of strings within our application. Javascript offers two popular methods designed for this purpose:
115180

0 commit comments

Comments
 (0)