From 4023ce3fde8fc45bb14c46fa317271e027914212 Mon Sep 17 00:00:00 2001 From: nsundriyal62 Date: Mon, 2 Oct 2023 20:39:47 +0530 Subject: [PATCH 1/6] Updated loop content for DSA folder --- content/batch/dsa/loops.mdx | 175 +++++++++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 2 deletions(-) diff --git a/content/batch/dsa/loops.mdx b/content/batch/dsa/loops.mdx index e8fdfa4..5c7bf58 100644 --- a/content/batch/dsa/loops.mdx +++ b/content/batch/dsa/loops.mdx @@ -4,6 +4,177 @@ description: Learn Loops in JavaScript --- +Want to improve this page? Raise an issue on [@github](https://github.com/FrontendFreaks/Official-Website). + -Want to improve this page?. Raise a issue on [@github](https://github.com/FrontendFreaks/Official-Website). - \ No newline at end of file +## What's on this section? + +In this section, you will: + +- 🎨 Explore different types of loops in JavaScript. +- πŸ” Understand the syntax and usage of for, while, and do-while loops. +- πŸ’‘ Learn about loop control statements like break and continue. +- πŸš€ Practice your knowledge through assignments related to loop concepts. + + + + + Learn + Assignment + + + + +### Explore Different Types of Loops + +In this section, you will dive into the various types of loops available in JavaScript, including: + +- **For Loop**: Learn how to use the `for` loop to execute code repeatedly. +- **While Loop**: Understand the `while` loop and how it differs from the `for` loop. +- **Do-While Loop**: Explore the `do-while` loop and its unique characteristics. +- **Loop Control Statements**: Discover how to control loops using `break` and `continue` statements. + +## πŸ“Ί Watch Now + +
+ + JavaScript Loops + +
+ +## πŸ“ Study Notes + +We've prepared detailed study notes to accompany the video. These notes cover essential concepts related to loops in JavaScript. Use them as a quick reference while learning or revising. + +### The `for` Loop + +The `for` loop is commonly used when you know the exact number of iterations you need. It consists of three parts: initialization, condition, and increment (or decrement). + +```javascript +for (let i = 0; i < 5; i++) { + text += "The number is " + i + "
"; +} + +``` +### The `for in` Loop + +The JavaScript for in statement loops through the properties of an Object: + +```javascript +const person = {fname:"John", lname:"Doe", age:25}; + +let text = ""; +for (let x in person) { + text += person[x]; +} + +``` +### The `for of` Loop + +The JavaScript for of statement loops through the values of an iterable object. + +It lets you loop over iterable data structures such as Arrays, Strings, Maps, NodeLists, and more: + +```javascript +const cars = ["BMW", "Volvo", "Mini"]; + +let text = ""; +for (let x of cars) { + text += x; +} + +``` + +### The `while` Loop + +The while loop loops through a block of code as long as a specified condition is true. + +```javascript +while (i < 10) { + text += "The number is " + i; + i++; +} + +``` + +### The ` do-while` Loop + +The do while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. + +```javascript +do { + text += "The number is " + i; + i++; +} +while (i < 10); + +``` +### The `Break` Statement + +The break statement can also be used to jump out of a loop + +```javascript +for (let i = 0; i < 10; i++) { + if (i === 3) { break; } + text += "The number is " + i + "
"; +} + +``` + +### The `continue` Statement + +The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop. + +```javascript +for (let i = 0; i < 10; i++) { + if (i === 3) { continue; } + text += "The number is " + i + "
"; +} + +``` + + +
+ + + +### Hands-On Assignments + +To reinforce your understanding of loops, we have prepared the following assignments for you: + + +### 1. Print Numbers with `for` Loop + +Write a `for` loop that prints numbers from 1 to 5. +### 2. Countdown with `while` Loop + +Create a `while` loop that counts down from 10 to 1. + +### 3. Iterate Through an Array + +Implement a `for` loop that iterates through an array and prints each element. + +### 4. Validate User Age with `do-while` Loop + +Write a `do-while` loop to prompt the user for their age until they enter a valid age (between 18 and 99). + + + +### 5. Calculate Sum of Even Numbers + +Create a `for` loop to calculate the sum of all even numbers from 1 to 10. + + +### 6. Generate Random Numbers + +Implement a `while` loop that generates random numbers between 1 and 100 until a number greater than 90 is generated. + + + +Feel free to try these exercises and test your knowledge of JavaScript loops! + +These assignments will help you solidify your knowledge of loops and improve your coding skills. + + + +
From 2539ea265d53e2dc58f92b37243c4d6e0c60065f Mon Sep 17 00:00:00 2001 From: nsundriyal62 Date: Wed, 4 Oct 2023 11:38:11 +0530 Subject: [PATCH 2/6] adding string in javascript dsa folder --- content/batch/dsa/string.mdx | 208 ++++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 4 deletions(-) diff --git a/content/batch/dsa/string.mdx b/content/batch/dsa/string.mdx index 92fac0d..53daf04 100644 --- a/content/batch/dsa/string.mdx +++ b/content/batch/dsa/string.mdx @@ -1,9 +1,209 @@ --- -title: String -description: Learn String in JavaScript +title: Strings +description: Learn Strings in JavaScript --- +Want to improve this page? Raise an issue on [@github](https://github.com/FrontendFreaks/Official-Website). + +## What's on this section? + +In this section, you will: + +- 🎨 Explore different string manipulation techniques in JavaScript. +- πŸ” Understand the various string methods and their usage. +- πŸ’‘ Learn about template literals and string interpolation. +- πŸš€ Practice your knowledge through assignments related to string manipulation. + + + + + Learn + Assignment + + + + +### Explore Different String Manipulation Techniques + +In this section, you will delve into various string manipulation techniques in JavaScript, including: + +- **String Methods**: Learn how to use various string methods for tasks like extracting, modifying, and searching for text within strings. +- **Template Literals**: Explore the power of template literals for creating dynamic strings with embedded expressions. +- **String Concatenation**: Understand how to concatenate strings using different methods. +- **String Interpolation**: Discover how to insert variables or expressions into strings effectively. + + +## πŸ“Ί Watch Now + +
+ + JavaScript Loops + +
+ +## πŸ“ Study Notes + +# String In JavaScript + + +### Length of a String +```javascript +let firstName = "Vaishali"; +console.log(firstName.length); +``` + +### Access String Element +```javascript +console.log(firstName.charAt(2)); // i +console.log(firstName[2]); // i +console.log(firstName.charCodeAt(2)); // 115 (Ascii Code) +``` + +### Check Presence of Character +```javascript +console.log(firstName.includes("r")); // false (& if present it return true) +console.log(firstName.indexOf("i")); // 2 (& if not present it return -1) +console.log(firstName.lastIndexOf("i")); // 7 +``` + +### Compare Two Strings +```javascript +let anotherName = "Vishal"; +console.log(firstName.localeCompare(anotherName)); // -1 (& if strings are equal it return 0) +``` + +### Replace Substring +```javascript +const str = "Vishal is Best Frontend Developer. Vishal is Best Developer. "; +console.log(str.replace("Vishal", "Sujit")); // "Sujit is Best Frontend Developer. Vishal is Best Developer. " +console.log(str.replaceAll("Vishal", "Sujit")); // "Sujit is Best Frontend Developer. Sujit is Best Developer. " +``` + +### Substring of a String +```javascript +console.log(str.substring(6, 30)); +console.log(str.slice(-10, -1)); +``` + +### Split and Join +```javascript +console.log(str.split("")); +const subString = str.split(" "); +console.log(subString.join(" ")); +``` + +### String Start and End +```javascript +console.log(str.startsWith("Vishal")); // true +console.log(str.endsWith("Developer")); // true +``` + +### Trim and Case Conversion +```javascript +const trimStr = str.trim(); +const trimStrStart = str.trimStart(); +const trimStrEnd = str.trimEnd(); +console.log(trimStr, trimStr.length); +console.log(str.toLowerCase()); +console.log(str.toUpperCase()); +``` + +### Convert Number and Object to String +```javascript +const num = 123; +console.log(num, num.toString()); + +const obj = { + name: "Vishal", + course: "DSA with Vishal" +}; +console.log(obj, JSON.stringify(obj)); +``` + +### Concatenate Strings +```javascript +const lastName = "Rajput"; +console.log(firstName + lastName); +console.log(`${firstName} ${lastName} is a Best Developer`); +console.log(firstName.concat(lastName, " is a", " Best")); +``` + +## Practice Questions + +- [Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/) +- [Reverse String](https://leetcode.com/problems/reverse-string) +- [Valid Anagram](https://leetcode.com/problems/valid-anagram) +- [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix) +- [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) +- [Length of Last Word](https://leetcode.com/problems/length-of-last-word/) +- [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) +- [String Compression](https://leetcode.com/problems/string-compression) +- [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) +- [Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string) +- [Rotate String](https://leetcode.com/problems/rotate-string) + + + +
+ + + + ### πŸ“ŒπŸ”¨ Task + + - Practice your string manipulation skills by solving the following problems. + - Use JavaScript to manipulate strings, extract information, and transform text. + + ### ❓Unclear with concepts? πŸ“Ί Watch This +
+ + String Manipulation in JavaScript + +
+ + + ### βš’οΈ Assignments for Practice + + πŸ‘¨β€πŸ’»πŸ“ Now that you have reviewed the string manipulation concepts, it's time to put your knowledge into practice by completing the string manipulation assignments. πŸš€ + + + + + Write a JavaScript function that reverses a given string. For example, if the input is "hello," the function should return "olleh." + + + + Implement a function that counts the number of vowels (a, e, i, o, u) in a given string. Ignore case sensitivity. For example, for the input "Hello World," the function should return 3. + + + + Create a function that checks if a given string is a palindrome. A palindrome is a word, phrase, or sequence of characters that reads the same backward as forward. For example, "racecar" is a palindrome. + + + + Write a function that finds the longest word in a sentence or string. For example, for the input "The quick brown fox jumped over the lazy dog," the function should return "jumped." + + + + Implement a function that converts a sentence to title case, where the first letter of each word is capitalized. For example, for the input "hello world," the function should return "Hello World." + + + + Create a function that generates a URL slug from a given string. A URL slug is a URL-friendly version of a string, typically used in URLs. For example, for the input "Learn JavaScript Basics," the function should return "learn-javascript-basics." + + + + ### πŸ“£ Done Solving? + πŸŽ‰ Congratulations on completing the string manipulation assignments! Share your solutions and showcase your skills. Connect with other developers and get feedback on your work. + + + πŸ‘ Great job mastering string manipulation in JavaScript! πŸŽ‰πŸ‘¨β€πŸ’»πŸ“ + + Now, you can continue your journey by exploring more advanced JavaScript topics or moving on to other aspects of web development. Keep coding and learning! πŸ’ͺπŸš€ + +
+ + +
+ -Want to improve this page?. Raise a issue on [@github](https://github.com/FrontendFreaks/Official-Website). - \ No newline at end of file From 6528b185aecb358117c31773c837d89ba4e6ec31 Mon Sep 17 00:00:00 2001 From: nsundriyal62 Date: Wed, 4 Oct 2023 16:07:03 +0530 Subject: [PATCH 3/6] Revert "adding string in javascript dsa folder" This reverts commit 2539ea265d53e2dc58f92b37243c4d6e0c60065f. --- content/batch/dsa/string.mdx | 208 +---------------------------------- 1 file changed, 4 insertions(+), 204 deletions(-) diff --git a/content/batch/dsa/string.mdx b/content/batch/dsa/string.mdx index 53daf04..92fac0d 100644 --- a/content/batch/dsa/string.mdx +++ b/content/batch/dsa/string.mdx @@ -1,209 +1,9 @@ --- -title: Strings -description: Learn Strings in JavaScript +title: String +description: Learn String in JavaScript --- -Want to improve this page? Raise an issue on [@github](https://github.com/FrontendFreaks/Official-Website). - -## What's on this section? - -In this section, you will: - -- 🎨 Explore different string manipulation techniques in JavaScript. -- πŸ” Understand the various string methods and their usage. -- πŸ’‘ Learn about template literals and string interpolation. -- πŸš€ Practice your knowledge through assignments related to string manipulation. - - - - - Learn - Assignment - - - - -### Explore Different String Manipulation Techniques - -In this section, you will delve into various string manipulation techniques in JavaScript, including: - -- **String Methods**: Learn how to use various string methods for tasks like extracting, modifying, and searching for text within strings. -- **Template Literals**: Explore the power of template literals for creating dynamic strings with embedded expressions. -- **String Concatenation**: Understand how to concatenate strings using different methods. -- **String Interpolation**: Discover how to insert variables or expressions into strings effectively. - - -## πŸ“Ί Watch Now - - - -## πŸ“ Study Notes - -# String In JavaScript - - -### Length of a String -```javascript -let firstName = "Vaishali"; -console.log(firstName.length); -``` - -### Access String Element -```javascript -console.log(firstName.charAt(2)); // i -console.log(firstName[2]); // i -console.log(firstName.charCodeAt(2)); // 115 (Ascii Code) -``` - -### Check Presence of Character -```javascript -console.log(firstName.includes("r")); // false (& if present it return true) -console.log(firstName.indexOf("i")); // 2 (& if not present it return -1) -console.log(firstName.lastIndexOf("i")); // 7 -``` - -### Compare Two Strings -```javascript -let anotherName = "Vishal"; -console.log(firstName.localeCompare(anotherName)); // -1 (& if strings are equal it return 0) -``` - -### Replace Substring -```javascript -const str = "Vishal is Best Frontend Developer. Vishal is Best Developer. "; -console.log(str.replace("Vishal", "Sujit")); // "Sujit is Best Frontend Developer. Vishal is Best Developer. " -console.log(str.replaceAll("Vishal", "Sujit")); // "Sujit is Best Frontend Developer. Sujit is Best Developer. " -``` - -### Substring of a String -```javascript -console.log(str.substring(6, 30)); -console.log(str.slice(-10, -1)); -``` - -### Split and Join -```javascript -console.log(str.split("")); -const subString = str.split(" "); -console.log(subString.join(" ")); -``` - -### String Start and End -```javascript -console.log(str.startsWith("Vishal")); // true -console.log(str.endsWith("Developer")); // true -``` - -### Trim and Case Conversion -```javascript -const trimStr = str.trim(); -const trimStrStart = str.trimStart(); -const trimStrEnd = str.trimEnd(); -console.log(trimStr, trimStr.length); -console.log(str.toLowerCase()); -console.log(str.toUpperCase()); -``` - -### Convert Number and Object to String -```javascript -const num = 123; -console.log(num, num.toString()); - -const obj = { - name: "Vishal", - course: "DSA with Vishal" -}; -console.log(obj, JSON.stringify(obj)); -``` - -### Concatenate Strings -```javascript -const lastName = "Rajput"; -console.log(firstName + lastName); -console.log(`${firstName} ${lastName} is a Best Developer`); -console.log(firstName.concat(lastName, " is a", " Best")); -``` - -## Practice Questions - -- [Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/) -- [Reverse String](https://leetcode.com/problems/reverse-string) -- [Valid Anagram](https://leetcode.com/problems/valid-anagram) -- [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix) -- [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) -- [Length of Last Word](https://leetcode.com/problems/length-of-last-word/) -- [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) -- [String Compression](https://leetcode.com/problems/string-compression) -- [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) -- [Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string) -- [Rotate String](https://leetcode.com/problems/rotate-string) - - - - - - - - ### πŸ“ŒπŸ”¨ Task - - - Practice your string manipulation skills by solving the following problems. - - Use JavaScript to manipulate strings, extract information, and transform text. - - ### ❓Unclear with concepts? πŸ“Ί Watch This -
- - String Manipulation in JavaScript - -
- - - ### βš’οΈ Assignments for Practice - - πŸ‘¨β€πŸ’»πŸ“ Now that you have reviewed the string manipulation concepts, it's time to put your knowledge into practice by completing the string manipulation assignments. πŸš€ - - - - - Write a JavaScript function that reverses a given string. For example, if the input is "hello," the function should return "olleh." - - - - Implement a function that counts the number of vowels (a, e, i, o, u) in a given string. Ignore case sensitivity. For example, for the input "Hello World," the function should return 3. - - - - Create a function that checks if a given string is a palindrome. A palindrome is a word, phrase, or sequence of characters that reads the same backward as forward. For example, "racecar" is a palindrome. - - - - Write a function that finds the longest word in a sentence or string. For example, for the input "The quick brown fox jumped over the lazy dog," the function should return "jumped." - - - - Implement a function that converts a sentence to title case, where the first letter of each word is capitalized. For example, for the input "hello world," the function should return "Hello World." - - - - Create a function that generates a URL slug from a given string. A URL slug is a URL-friendly version of a string, typically used in URLs. For example, for the input "Learn JavaScript Basics," the function should return "learn-javascript-basics." - - - - ### πŸ“£ Done Solving? - πŸŽ‰ Congratulations on completing the string manipulation assignments! Share your solutions and showcase your skills. Connect with other developers and get feedback on your work. - - - πŸ‘ Great job mastering string manipulation in JavaScript! πŸŽ‰πŸ‘¨β€πŸ’»πŸ“ - - Now, you can continue your journey by exploring more advanced JavaScript topics or moving on to other aspects of web development. Keep coding and learning! πŸ’ͺπŸš€ - -
- - -
- +Want to improve this page?. Raise a issue on [@github](https://github.com/FrontendFreaks/Official-Website). + \ No newline at end of file From 1cadf6f493f965c4b54be7665c47275f08b5945f Mon Sep 17 00:00:00 2001 From: nsundriyal62 Date: Wed, 4 Oct 2023 16:07:31 +0530 Subject: [PATCH 4/6] rewritting loops content for dsa --- content/batch/dsa/loops.mdx | 175 +----------------------------------- 1 file changed, 2 insertions(+), 173 deletions(-) diff --git a/content/batch/dsa/loops.mdx b/content/batch/dsa/loops.mdx index 5c7bf58..e8fdfa4 100644 --- a/content/batch/dsa/loops.mdx +++ b/content/batch/dsa/loops.mdx @@ -4,177 +4,6 @@ description: Learn Loops in JavaScript --- -Want to improve this page? Raise an issue on [@github](https://github.com/FrontendFreaks/Official-Website). - -## What's on this section? - -In this section, you will: - -- 🎨 Explore different types of loops in JavaScript. -- πŸ” Understand the syntax and usage of for, while, and do-while loops. -- πŸ’‘ Learn about loop control statements like break and continue. -- πŸš€ Practice your knowledge through assignments related to loop concepts. - - - - - Learn - Assignment - - - - -### Explore Different Types of Loops - -In this section, you will dive into the various types of loops available in JavaScript, including: - -- **For Loop**: Learn how to use the `for` loop to execute code repeatedly. -- **While Loop**: Understand the `while` loop and how it differs from the `for` loop. -- **Do-While Loop**: Explore the `do-while` loop and its unique characteristics. -- **Loop Control Statements**: Discover how to control loops using `break` and `continue` statements. - -## πŸ“Ί Watch Now - - - -## πŸ“ Study Notes - -We've prepared detailed study notes to accompany the video. These notes cover essential concepts related to loops in JavaScript. Use them as a quick reference while learning or revising. - -### The `for` Loop - -The `for` loop is commonly used when you know the exact number of iterations you need. It consists of three parts: initialization, condition, and increment (or decrement). - -```javascript -for (let i = 0; i < 5; i++) { - text += "The number is " + i + "
"; -} - -``` -### The `for in` Loop - -The JavaScript for in statement loops through the properties of an Object: - -```javascript -const person = {fname:"John", lname:"Doe", age:25}; - -let text = ""; -for (let x in person) { - text += person[x]; -} - -``` -### The `for of` Loop - -The JavaScript for of statement loops through the values of an iterable object. - -It lets you loop over iterable data structures such as Arrays, Strings, Maps, NodeLists, and more: - -```javascript -const cars = ["BMW", "Volvo", "Mini"]; - -let text = ""; -for (let x of cars) { - text += x; -} - -``` - -### The `while` Loop - -The while loop loops through a block of code as long as a specified condition is true. - -```javascript -while (i < 10) { - text += "The number is " + i; - i++; -} - -``` - -### The ` do-while` Loop - -The do while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. - -```javascript -do { - text += "The number is " + i; - i++; -} -while (i < 10); - -``` -### The `Break` Statement - -The break statement can also be used to jump out of a loop - -```javascript -for (let i = 0; i < 10; i++) { - if (i === 3) { break; } - text += "The number is " + i + "
"; -} - -``` - -### The `continue` Statement - -The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop. - -```javascript -for (let i = 0; i < 10; i++) { - if (i === 3) { continue; } - text += "The number is " + i + "
"; -} - -``` - - -
- - - -### Hands-On Assignments - -To reinforce your understanding of loops, we have prepared the following assignments for you: - - -### 1. Print Numbers with `for` Loop - -Write a `for` loop that prints numbers from 1 to 5. -### 2. Countdown with `while` Loop - -Create a `while` loop that counts down from 10 to 1. - -### 3. Iterate Through an Array - -Implement a `for` loop that iterates through an array and prints each element. - -### 4. Validate User Age with `do-while` Loop - -Write a `do-while` loop to prompt the user for their age until they enter a valid age (between 18 and 99). - - - -### 5. Calculate Sum of Even Numbers - -Create a `for` loop to calculate the sum of all even numbers from 1 to 10. - - -### 6. Generate Random Numbers - -Implement a `while` loop that generates random numbers between 1 and 100 until a number greater than 90 is generated. - - - -Feel free to try these exercises and test your knowledge of JavaScript loops! - -These assignments will help you solidify your knowledge of loops and improve your coding skills. - - - -
+Want to improve this page?. Raise a issue on [@github](https://github.com/FrontendFreaks/Official-Website). + \ No newline at end of file From 5ff061efb8fb1d59949a550b1724f86a54c1c386 Mon Sep 17 00:00:00 2001 From: nsundriyal62 Date: Wed, 4 Oct 2023 16:23:41 +0530 Subject: [PATCH 5/6] string content changed in dsa folder --- content/batch/dsa/string.mdx | 147 ++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 4 deletions(-) diff --git a/content/batch/dsa/string.mdx b/content/batch/dsa/string.mdx index 92fac0d..5b562b1 100644 --- a/content/batch/dsa/string.mdx +++ b/content/batch/dsa/string.mdx @@ -1,9 +1,148 @@ --- -title: String -description: Learn String in JavaScript +title: Strings +description: Learn Strings in JavaScript --- +Want to improve this page? Raise an issue on [@github](https://github.com/FrontendFreaks/Official-Website). + +## What's on this section? + +In this section, you will: + +- 🎨 Explore different string manipulation techniques in JavaScript. +- πŸ” Understand the various string methods and their usage. +- πŸ’‘ Learn about template literals and string interpolation. +- πŸš€ Practice your knowledge through assignments related to string manipulation. + + + + + Learn + Assignment + + + + +## πŸ“Ί Watch Now + + + + + We hope that you found the tutorial video helpful in understanding the basic concepts of Strings in java, You can refer this notes πŸ“ for quick revision. + + +## πŸ“ Study Notes + +# String In JavaScript + + +### Length of a String +```javascript +let firstName = "Vaishali"; +console.log(firstName.length); +``` + +### Access String Element +```javascript +console.log(firstName.charAt(2)); // i +console.log(firstName[2]); // i +console.log(firstName.charCodeAt(2)); // 115 (Ascii Code) +``` + +### Check Presence of Character +```javascript +console.log(firstName.includes("r")); // false (& if present it return true) +console.log(firstName.indexOf("i")); // 2 (& if not present it return -1) +console.log(firstName.lastIndexOf("i")); // 7 +``` + +### Compare Two Strings +```javascript +let anotherName = "Vishal"; +console.log(firstName.localeCompare(anotherName)); // -1 (& if strings are equal it return 0) +``` + +### Replace Substring +```javascript +const str = "Vishal is Best Frontend Developer. Vishal is Best Developer. "; +console.log(str.replace("Vishal", "Sujit")); // "Sujit is Best Frontend Developer. Vishal is Best Developer. " +console.log(str.replaceAll("Vishal", "Sujit")); // "Sujit is Best Frontend Developer. Sujit is Best Developer. " +``` + +### Substring of a String +```javascript +console.log(str.substring(6, 30)); +console.log(str.slice(-10, -1)); +``` + +### Split and Join +```javascript +console.log(str.split("")); +const subString = str.split(" "); +console.log(subString.join(" ")); +``` + +### String Start and End +```javascript +console.log(str.startsWith("Vishal")); // true +console.log(str.endsWith("Developer")); // true +``` + +### Trim and Case Conversion +```javascript +const trimStr = str.trim(); +const trimStrStart = str.trimStart(); +const trimStrEnd = str.trimEnd(); +console.log(trimStr, trimStr.length); +console.log(str.toLowerCase()); +console.log(str.toUpperCase()); +``` + +### Convert Number and Object to String +```javascript +const num = 123; +console.log(num, num.toString()); + +const obj = { + name: "Vishal", + course: "DSA with Vishal" +}; +console.log(obj, JSON.stringify(obj)); +``` + +### Concatenate Strings +```javascript +const lastName = "Rajput"; +console.log(firstName + lastName); +console.log(`${firstName} ${lastName} is a Best Developer`); +console.log(firstName.concat(lastName, " is a", " Best")); +``` + + + + + +## Practice Questions + +- [Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/) +- [Reverse String](https://leetcode.com/problems/reverse-string) +- [Valid Anagram](https://leetcode.com/problems/valid-anagram) +- [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix) +- [Merge Strings Alternately](https://leetcode.com/problems/merge-strings-alternately) +- [Length of Last Word](https://leetcode.com/problems/length-of-last-word/) +- [Valid Palindrome](https://leetcode.com/problems/valid-palindrome) +- [String Compression](https://leetcode.com/problems/string-compression) +- [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string) +- [Reverse Vowels of a String](https://leetcode.com/problems/reverse-vowels-of-a-string) +- [Rotate String](https://leetcode.com/problems/rotate-string) + + + + + -Want to improve this page?. Raise a issue on [@github](https://github.com/FrontendFreaks/Official-Website). - \ No newline at end of file From 70f4baed12fa868a9cfa7c7d8487f7af81a1385f Mon Sep 17 00:00:00 2001 From: nsundriyal62 Date: Wed, 4 Oct 2023 19:05:47 +0530 Subject: [PATCH 6/6] Revert "string content changed in dsa folder" This reverts commit 5ff061efb8fb1d59949a550b1724f86a54c1c386. modified: content/batch/dsa/string.mdx --- content/batch/dsa/string.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/batch/dsa/string.mdx b/content/batch/dsa/string.mdx index 5b562b1..84cf8df 100644 --- a/content/batch/dsa/string.mdx +++ b/content/batch/dsa/string.mdx @@ -26,9 +26,10 @@ In this section, you will: ## πŸ“Ί Watch Now +