From a61400de658dc44c11c33d0a865027c3b4d18e09 Mon Sep 17 00:00:00 2001 From: Aditya Kumar <146847363+aditya-23140@users.noreply.github.com> Date: Mon, 10 Feb 2025 01:01:46 +0530 Subject: [PATCH] Added missing solutions for problems in #video 83 Sir, I have tried to solve all questions on my own and now I am uploading all the solution. Please merge it if my solutions are ok. Thank you, Aditya --- Video 83/Solutions/02_solve.js | 9 ++ Video 83/Solutions/03_solve.js | 10 ++ Video 83/Solutions/04_solve.js | 36 ++++++++ Video 83/Solutions/05_solve.js | 8 ++ Video 83/Solutions/06_solve.js | 8 ++ Video 83/Solutions/08_solve.html | 30 ++++++ Video 83/Solutions/09_solve.html | 41 ++++++++ Video 83/Solutions/10_solve.html | 37 ++++++++ Video 83/Solutions/11_solve.html | 154 +++++++++++++++++++++++++++++++ Video 83/Solutions/12_solve.html | 39 ++++++++ Video 83/Solutions/13_solve.html | 64 +++++++++++++ Video 83/Solutions/14_solve.html | 35 +++++++ 12 files changed, 471 insertions(+) create mode 100644 Video 83/Solutions/02_solve.js create mode 100644 Video 83/Solutions/03_solve.js create mode 100644 Video 83/Solutions/04_solve.js create mode 100644 Video 83/Solutions/05_solve.js create mode 100644 Video 83/Solutions/06_solve.js create mode 100644 Video 83/Solutions/08_solve.html create mode 100644 Video 83/Solutions/09_solve.html create mode 100644 Video 83/Solutions/10_solve.html create mode 100644 Video 83/Solutions/11_solve.html create mode 100644 Video 83/Solutions/12_solve.html create mode 100644 Video 83/Solutions/13_solve.html create mode 100644 Video 83/Solutions/14_solve.html diff --git a/Video 83/Solutions/02_solve.js b/Video 83/Solutions/02_solve.js new file mode 100644 index 0000000..a3ad73f --- /dev/null +++ b/Video 83/Solutions/02_solve.js @@ -0,0 +1,9 @@ +let arr = [1, 2, 2, 3, 44, 54, 33, 44, 12, 2, 45]; +let copy = [...arr]; +arr[0] *= 2; +for (let index = 1; index < arr.length; index++) { + if (arr[index] !== copy[index - 1]) { + arr[index] *= 2; + } +} +console.log(arr); diff --git a/Video 83/Solutions/03_solve.js b/Video 83/Solutions/03_solve.js new file mode 100644 index 0000000..c954af8 --- /dev/null +++ b/Video 83/Solutions/03_solve.js @@ -0,0 +1,10 @@ +const reverse = (string) => { + let newString = ""; + for (let i = string.length - 1; i >= 0; i--) { + newString += string[i]; + } + return newString; +}; + +let result = reverse("Aditya"); +console.log(result); diff --git a/Video 83/Solutions/04_solve.js b/Video 83/Solutions/04_solve.js new file mode 100644 index 0000000..01d38d8 --- /dev/null +++ b/Video 83/Solutions/04_solve.js @@ -0,0 +1,36 @@ +let password = "Aditya@2005"; + +const passwordValidator = (password) => { + const regex = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[\W_])[A-Za-z\d\W_]{8,}$/; + // Regex Breakdown + // ^ → Start of the string + // (?=.*[A-Z]) → At least one uppercase letter + // (?=.*[a-z]) → At least one lowercase letter + // (?=.*\d) → At least one digit + // (?=.*[\W_]) → At least one special character (\W matches any non-word character, _ is included explicitly) + // [A-Za-z\d\W_]{8,} → Matches atleast 8 characters (letters, numbers, and special characters) + // $ → End of the string + return regex.test(password); +}; + +//Alternate +function isValidString(str) { + if (str.length < 8) return false; + + let hasUpper = false, + hasLower = false, + hasDigit = false, + hasSpecial = false; + + for (let char of str) { + if (/[A-Z]/.test(char)) hasUpper = true; + if (/[a-z]/.test(char)) hasLower = true; + if (/\d/.test(char)) hasDigit = true; + if (/[\W_]/.test(char)) hasSpecial = true; + } + + return hasUpper && hasLower && hasDigit && hasSpecial; +} + +console.log(passwordValidator(password)); +console.log(isValidString(password)); diff --git a/Video 83/Solutions/05_solve.js b/Video 83/Solutions/05_solve.js new file mode 100644 index 0000000..673e8dd --- /dev/null +++ b/Video 83/Solutions/05_solve.js @@ -0,0 +1,8 @@ +let arr = [1, 23, 12, 44, -23, 67]; +let sum = 0; +for (const element of arr) { + if (element >= 0) sum += element; + else break; +} + +console.log(sum); diff --git a/Video 83/Solutions/06_solve.js b/Video 83/Solutions/06_solve.js new file mode 100644 index 0000000..a092a05 --- /dev/null +++ b/Video 83/Solutions/06_solve.js @@ -0,0 +1,8 @@ +const vowels = "aeiouAEIOU"; +let string = "Aditya Kumar Singh"; +let count = 0; +for (const element of string) { + if (vowels.includes(element)) count++; +} + +console.log(count); diff --git a/Video 83/Solutions/08_solve.html b/Video 83/Solutions/08_solve.html new file mode 100644 index 0000000..0c89bed --- /dev/null +++ b/Video 83/Solutions/08_solve.html @@ -0,0 +1,30 @@ + + + +
+ + +ID | +Name | +Category | +Price ($) | +Stock | +Rating | +
---|