You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-6Lines changed: 71 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,10 +3,10 @@
3
3
### This is open-source Project
4
4
__If you want to contribute then follow theses steps__
5
5
>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>
10
10
11
11
12
12
__Algorithms practiced using JS__
@@ -87,10 +87,72 @@ We will now explore ways to solve this challenge below. They are:
87
87
<hr>
88
88
<b>2. Vowel counter </b>
89
89
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
+
constvowel= ["a", "e", "i", "o", "u"];
124
+
125
+
functionvowelcnt(text) {
126
+
let counter =0;
127
+
128
+
//Loop through text to test if each character is a vowel
129
+
for (let letter oftext.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
+
91
154
92
155
93
-
__Algorithmic Thinking:__ <p> </p>
94
156
95
157
96
158
<hr>
@@ -106,10 +168,13 @@ maxRecurringChar('aabacada') // will return 'a'
106
168
```
107
169
108
170
__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>
109
172
173
+
__Code Implementation:__
110
174
111
175
<hr>
112
176
<hr>
177
+
113
178
<b>4. Sentence Capitalization</b>
114
179
<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:
0 commit comments