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
+61
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,8 @@ All of these examples are from FreeCodeCamp's [course](https://www.freecodecamp.
16
16
-[3. Factorialize a Number](#3-factorialize-a-number)
17
17
-[4. Find the Longest Word in a String](#4-find-the-longest-word-in-a-string)
18
18
-[5. Return Largest Numbers in Arrays Passed](#5-return-largest-numbers-in-arrays-passed)
19
+
-[6. Confirm the Ending Passed](#6-confirm-the-ending-passed)
20
+
-[7. Repeat a String Repeat a String](#7-repeat-a-string-repeat-a-string)
19
21
20
22
## Basic Algorithm Scripting
21
23
@@ -201,3 +203,62 @@ largestOfFour([
201
203
[1000, 1001, 857, 1],
202
204
]);
203
205
```
206
+
207
+
### 6. Confirm the Ending Passed
208
+
209
+
_Difficulty: Beginner_
210
+
211
+
Check if a string (first argument, str) ends with the given target string (second argument, target).
212
+
213
+
This challenge can be solved with the .endsWith() method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead.
214
+
215
+
---
216
+
217
+
#### Solution
218
+
219
+
```js
220
+
functionconfirmEnding(str, target) {
221
+
return target ===str.substr(-target.length);
222
+
}
223
+
224
+
confirmEnding("Bastian", "n");
225
+
```
226
+
227
+
### 7. Repeat a String Repeat a String
228
+
229
+
_Difficulty: Beginner_
230
+
231
+
Repeat a given string str (first argument) for num times (second argument). Return an empty string if num is not a positive number. For the purpose of this challenge, do not use the built-in .repeat() method.
0 commit comments