From ae3e9e50f44de0200eff60e3cd3ae1d90413c12c Mon Sep 17 00:00:00 2001 From: Manish Choudhary Date: Sun, 19 Jan 2025 13:44:21 +0000 Subject: [PATCH 1/3] First two exercises are done --- 01-basic-challenges-1/01-hello-world/hello-world.js | 4 +++- .../{hello-world-test.js => hello-world.test.js} | 0 01-basic-challenges-1/02-get-sum/get-sum.js | 4 +++- .../02-get-sum/{get-sum-test.js => get-sum.test.js} | 0 4 files changed, 6 insertions(+), 2 deletions(-) rename 01-basic-challenges-1/01-hello-world/{hello-world-test.js => hello-world.test.js} (100%) rename 01-basic-challenges-1/02-get-sum/{get-sum-test.js => get-sum.test.js} (100%) diff --git a/01-basic-challenges-1/01-hello-world/hello-world.js b/01-basic-challenges-1/01-hello-world/hello-world.js index 746f414..a232514 100644 --- a/01-basic-challenges-1/01-hello-world/hello-world.js +++ b/01-basic-challenges-1/01-hello-world/hello-world.js @@ -1,3 +1,5 @@ -function helloWorld() {} +function helloWorld() { + return "Hello World!" +} module.exports = helloWorld; diff --git a/01-basic-challenges-1/01-hello-world/hello-world-test.js b/01-basic-challenges-1/01-hello-world/hello-world.test.js similarity index 100% rename from 01-basic-challenges-1/01-hello-world/hello-world-test.js rename to 01-basic-challenges-1/01-hello-world/hello-world.test.js diff --git a/01-basic-challenges-1/02-get-sum/get-sum.js b/01-basic-challenges-1/02-get-sum/get-sum.js index 73453d5..52fdbfa 100644 --- a/01-basic-challenges-1/02-get-sum/get-sum.js +++ b/01-basic-challenges-1/02-get-sum/get-sum.js @@ -1,3 +1,5 @@ -function getSum() {} +function getSum(a, b) { + return a+b +} module.exports = getSum; diff --git a/01-basic-challenges-1/02-get-sum/get-sum-test.js b/01-basic-challenges-1/02-get-sum/get-sum.test.js similarity index 100% rename from 01-basic-challenges-1/02-get-sum/get-sum-test.js rename to 01-basic-challenges-1/02-get-sum/get-sum.test.js From 04b90153ef8f09bd2585abf0583f7d58589f30fe Mon Sep 17 00:00:00 2001 From: Manish Choudhary Date: Sun, 19 Jan 2025 14:36:51 +0000 Subject: [PATCH 2/3] Some more exercises are complete now --- .../03-calculator/calculator.js | 16 ++++++++++++- ...{calculator-test.js => calculator.test.js} | 0 .../04-count-occurrences/count-occurrences.js | 10 +++++++- ...nces-test.js => count-occurrences.test.js} | 0 .../05-find-max-number/find-max-number.js | 12 +++++++++- ...number-test.js => find-max-number.test.js} | 0 .../06-title-case/title-case.js | 23 ++++++++++++++++++- ...{title-case-test.js => title-case.test.js} | 0 8 files changed, 57 insertions(+), 4 deletions(-) rename 01-basic-challenges-1/03-calculator/{calculator-test.js => calculator.test.js} (100%) rename 01-basic-challenges-1/04-count-occurrences/{count-occurrences-test.js => count-occurrences.test.js} (100%) rename 01-basic-challenges-1/05-find-max-number/{find-max-number-test.js => find-max-number.test.js} (100%) rename 01-basic-challenges-1/06-title-case/{title-case-test.js => title-case.test.js} (100%) diff --git a/01-basic-challenges-1/03-calculator/calculator.js b/01-basic-challenges-1/03-calculator/calculator.js index 5f8f9c6..ecedd50 100644 --- a/01-basic-challenges-1/03-calculator/calculator.js +++ b/01-basic-challenges-1/03-calculator/calculator.js @@ -1,3 +1,17 @@ -function calculator() {} +function calculator(num1, num2, operator) { + switch(operator) { + case "+": + return num1+num2; + case "-": + return num1 - num2; + case "*": + return num1 * num2; + case "/": + return num1 / num2; + default: + throw new Error(`Unknown operator ${operator}`) + } + +} module.exports = calculator; diff --git a/01-basic-challenges-1/03-calculator/calculator-test.js b/01-basic-challenges-1/03-calculator/calculator.test.js similarity index 100% rename from 01-basic-challenges-1/03-calculator/calculator-test.js rename to 01-basic-challenges-1/03-calculator/calculator.test.js diff --git a/01-basic-challenges-1/04-count-occurrences/count-occurrences.js b/01-basic-challenges-1/04-count-occurrences/count-occurrences.js index c5f47ae..f9a0ca2 100644 --- a/01-basic-challenges-1/04-count-occurrences/count-occurrences.js +++ b/01-basic-challenges-1/04-count-occurrences/count-occurrences.js @@ -1,3 +1,11 @@ -function countOccurrences() {} +function countOccurrences(text, search) { + let result = 0 + for(let i=0; i Date: Sun, 19 Jan 2025 15:02:24 +0000 Subject: [PATCH 3/3] Solved more problems --- .../07-reverse-string/reverse-string.js | 10 +++++++++- ...-string-test.js => reverse-string.test.js} | 0 .../08-palindrome/palindrome.js | 20 ++++++++++++++++++- ...{palindrome-test.js => palindrome.test.js} | 0 4 files changed, 28 insertions(+), 2 deletions(-) rename 01-basic-challenges-1/07-reverse-string/{reverse-string-test.js => reverse-string.test.js} (100%) rename 01-basic-challenges-1/08-palindrome/{palindrome-test.js => palindrome.test.js} (100%) diff --git a/01-basic-challenges-1/07-reverse-string/reverse-string.js b/01-basic-challenges-1/07-reverse-string/reverse-string.js index ab5349e..21f6f73 100644 --- a/01-basic-challenges-1/07-reverse-string/reverse-string.js +++ b/01-basic-challenges-1/07-reverse-string/reverse-string.js @@ -1,3 +1,11 @@ -function reverseString() {} +function reverseString(str) { + let len = str.length - 1 + let result = '' + for(let i=len; i >=0; i-- ) { + result += str[i] + } + + return result +} module.exports = reverseString; diff --git a/01-basic-challenges-1/07-reverse-string/reverse-string-test.js b/01-basic-challenges-1/07-reverse-string/reverse-string.test.js similarity index 100% rename from 01-basic-challenges-1/07-reverse-string/reverse-string-test.js rename to 01-basic-challenges-1/07-reverse-string/reverse-string.test.js diff --git a/01-basic-challenges-1/08-palindrome/palindrome.js b/01-basic-challenges-1/08-palindrome/palindrome.js index e3ffb15..9a4c043 100644 --- a/01-basic-challenges-1/08-palindrome/palindrome.js +++ b/01-basic-challenges-1/08-palindrome/palindrome.js @@ -1,3 +1,21 @@ -function isPalindrome() {} +function isPalindrome(str) { + + str = str.toLowerCase() + str = str.replace(/[^a-z0-9]/g,"") + let [left,right ]= [0, str.length -1] + + let result = true + while(left<=right) { + if(str[left]!=str[right]) { + result = false + break + } else { + left++ + right-- + } + } + + return result +} module.exports = isPalindrome; diff --git a/01-basic-challenges-1/08-palindrome/palindrome-test.js b/01-basic-challenges-1/08-palindrome/palindrome.test.js similarity index 100% rename from 01-basic-challenges-1/08-palindrome/palindrome-test.js rename to 01-basic-challenges-1/08-palindrome/palindrome.test.js