From 3d6a62d5cdd6d6db9f6a3609099c59864a6eb284 Mon Sep 17 00:00:00 2001 From: "[Jay Pandya]" Date: Sat, 28 Oct 2023 13:48:56 +0530 Subject: [PATCH 1/2] made some changes --- DSA/Arrays/BubbleSort.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSA/Arrays/BubbleSort.js b/DSA/Arrays/BubbleSort.js index c37a9d6..509e86e 100644 --- a/DSA/Arrays/BubbleSort.js +++ b/DSA/Arrays/BubbleSort.js @@ -1,4 +1,4 @@ -// Bubble sort Implementation using Javascript +// Bubble sort Implementation using Javascript //code function bblSort(arr){ From 2726f147a3eab11cd5f7488d0f4cd46dd8220632 Mon Sep 17 00:00:00 2001 From: "[Jay Pandya]" Date: Sat, 28 Oct 2023 15:57:47 +0530 Subject: [PATCH 2/2] Added a String DSA example --- DSA/Strings/LargestOddNumber.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 DSA/Strings/LargestOddNumber.js diff --git a/DSA/Strings/LargestOddNumber.js b/DSA/Strings/LargestOddNumber.js new file mode 100644 index 0000000..720fd07 --- /dev/null +++ b/DSA/Strings/LargestOddNumber.js @@ -0,0 +1,30 @@ +// Javascript code for the above approach + +// returns a substring that contains the maximum odd number at its end +function maxOdd(s) { + + // Loop through the string backwards, starting from the end + for (let i = s.length - 1; i >= 0; i--) { + + // Check if the current character is odd + if (parseInt(s.charAt(i)) % 2 !== 0) { + + // If it is, return the substring that contains + // all the characters up to and including the current character + return s.substring(0, i + 1); + } + } + + // If no odd number is found in the string, return an empty string + return ''; + } + + // driver function + + const s = '504'; + // function call + const ans = maxOdd(s); + console.log(ans); + + // This code is contributed by Vaibhav Nandan. + \ No newline at end of file