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 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=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