├── Day-01 ├── README.md └── index.js ├── Day-02 ├── README.md └── index.js ├── Day-03 ├── README.md └── index.js ├── Day-04 ├── README.md ├── index.js ├── index2.js └── index3.js ├── Day-05 ├── README.md └── index.js ├── Day-06 ├── README.md └── index.js ├── Day-07 ├── README.md └── index.js ├── Day-08 ├── README.md └── index.js ├── Day-09 ├── README.md └── index.js ├── Day-10 ├── README.md └── index.js ├── Day-11 ├── README.md └── index.js ├── Day-12 ├── README.md └── index.js ├── Day-13 ├── README.md └── index.js ├── Day-14 ├── README.md └── index.js ├── Day-15 ├── README.md └── index.js ├── Day-16 ├── README.md └── index.js ├── Day-17 ├── README.md └── index.js ├── Day-18 ├── README.md └── index.js ├── Day-19 ├── README.md └── index.js ├── Day-20 ├── README.md └── index.js ├── Day-21 ├── README.md └── index.js ├── Day-22 ├── README.md └── index.js ├── Day-23 ├── README.md └── index.js ├── Day-24 ├── README.md └── index.js ├── Day-25 ├── README.md └── index.js ├── Day-26 ├── README.md └── index.js ├── Day-27 ├── README.md └── index.js ├── Day-28 ├── README.md └── index.js ├── Day-29 ├── README.md └── index.js ├── Day-30 ├── README.md └── index.js ├── Day-31 ├── README.md └── index.js ├── Day-32 ├── README.md └── index.js ├── Day-33 ├── README.md └── index.js ├── Day-34 ├── README.md └── index.js ├── Day-35 ├── README.md └── index.js ├── Day-36 ├── README.md └── index.js ├── Day-37 ├── README.md └── index.js ├── Day-38 ├── README.md └── index.js ├── Day-39 ├── README.md └── index.js ├── Day-40 ├── README.md └── index.js ├── Day-41 ├── README.md └── index.js ├── Day-42 ├── README.md └── index.js ├── Day-43 ├── README.md ├── index.js └── index1.js ├── Day-44 ├── README.md └── index.js ├── Day-45 ├── README.md └── index.js ├── Day-46 ├── README.md └── index.js ├── Day-47 ├── README.md └── index.js ├── Day-48 ├── README.md └── index.js ├── Day-49 ├── README.md └── index.js ├── Day-50 ├── README.md └── index.js ├── LICENSE └── README.md /Day-01/README.md: -------------------------------------------------------------------------------- 1 | # Function which returns a random number in the given range 2 | Create a function which returns a random number in the given range of values both inclusive 3 | 4 | ## Challenges (0/2 done) 5 | - [ ] randomNumberGeneratorInRange(10, 50) should return a number between 10-50 (inclusive) 6 | - [ ] randomNumberGeneratorInRange(100, 200) should return a number between 100-200 (inclusive) 7 | 8 | ```js 9 | function randomNumberGeneratorInRange(min, max) { 10 | // write your solution here 11 | 12 | return 13 | } 14 | 15 | console.log(`My random number: ${randomNumberGeneratorInRange(5, 100)}`) 16 | ``` 17 | 18 | [Resource-1](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) 19 | [Resource-2](https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range) 20 | -------------------------------------------------------------------------------- /Day-01/index.js: -------------------------------------------------------------------------------- 1 | function randomNumberGeneratorInRange(min, max) { 2 | // write your solution here 3 | 4 | return Math.floor(Math.random() * (max - min + 1)) + min 5 | } 6 | 7 | console.log(`My random number: ${randomNumberGeneratorInRange(5, 100)}`) 8 | -------------------------------------------------------------------------------- /Day-02/README.md: -------------------------------------------------------------------------------- 1 | # Write a program to reverse a string 2 | + String can be reversed by iterating it and storing it in reverse order 3 | + String can also be reversed by converting it to array, then joining it after reversing 4 | 5 | ## Challenges (0/3 done) 6 | - [ ] reverseAString("JavaScript is awesome") should return "emosewa si tpircSavaJ" 7 | - [ ] reverseAString("Peter Parker is Spiderman") should return "namredipS si rekraP reteP" 8 | - [ ] reverseAString("codedamn") should return "nmadedoc" 9 | 10 | ```js 11 | const str = "JavaScript is awesome" 12 | 13 | function reverseAString(str) { 14 | // write your solution here 15 | 16 | return 17 | } 18 | 19 | console.log(`Reversed string is: ${reverseAString(str)}`) 20 | ``` 21 | -------------------------------------------------------------------------------- /Day-02/index.js: -------------------------------------------------------------------------------- 1 | const str = "JavaScript is awesome" 2 | 3 | function reverseAString(str) { 4 | // write your solution here 5 | let reversed = "" 6 | for (let i = str.length - 1; i >= 0; i--) { 7 | reversed += str[i]; 8 | } 9 | 10 | return reversed; 11 | } 12 | 13 | console.log(`Reversed string is: ${reverseAString(str)}`) 14 | -------------------------------------------------------------------------------- /Day-03/README.md: -------------------------------------------------------------------------------- 1 | # Write a program to reverse a given integer number 2 | * The remainder of the number can be fetched and the number can be divided by 10 to remove the the digit in loop till number becomes 0 3 | * A simple approach to reverse a number could also be to convert it in to a string and then reverse it 4 | 5 | ## Challenges (0/3 done) 6 | * [ ] reverseGivenInteger(3849) returns 9483 7 | * [ ] reverseGivenInteger(2222) returns 2222 8 | * [ ] reverseGivenInteger(1002) returns 2001 9 | 10 | ```js 11 | const num = 3849; 12 | 13 | function reverseGivenInteger(num) { 14 | // write your solution here 15 | 16 | return 17 | } 18 | 19 | console.log(`Reversed integer is: ${reverseGivenInteger(num)}`) 20 | ``` 21 | -------------------------------------------------------------------------------- /Day-03/index.js: -------------------------------------------------------------------------------- 1 | const num = 3849; 2 | 3 | function reverseGivenInteger(num) { 4 | // write your solution here 5 | let st = num.toString(); 6 | let rev_num = st.split('').reverse().join(''); 7 | return Number(rev_num); 8 | } 9 | 10 | console.log(`Reversed integer is: ${reverseGivenInteger(num)}`) 11 | -------------------------------------------------------------------------------- /Day-04/README.md: -------------------------------------------------------------------------------- 1 | # Write a function which can convert the time input given in 12 hours format to 24 hours format 2 | * The check for 'AM' and 'PM' can be verified using endsWith String method 3 | * An extra 0 would be needed if the hours have single digit 4 | 5 | ## Challenges (0/6 done) 6 | * [ ] convertTo24HrsFormat("12:10AM") returns "00:10" 7 | * [ ] convertTo24HrsFormat("5:00AM") returns "05:00" 8 | * [ ] convertTo24HrsFormat("12:33PM") returns "12:33" 9 | * [ ] convertTo24HrsFormat("01:59PM") returns "13:59" 10 | * [ ] convertTo24HrsFormat("11:8PM") returns "23:08" 11 | * [ ] convertTo24HrsFormat("10:02PM") returns "22:02" 12 | 13 | ```js 14 | const time = '12:10AM'; 15 | 16 | function convertTo24HrsFormat(time) { 17 | // write your solution here 18 | 19 | return 20 | } 21 | 22 | console.log(`Converted time: ${convertTo24HrsFormat(time)}`) 23 | ``` 24 | -------------------------------------------------------------------------------- /Day-04/index.js: -------------------------------------------------------------------------------- 1 | const time = '12:10AM'; 2 | 3 | function convertTo24HrsFormat(time) { 4 | // write your solution here 5 | if (time.length === 6) { 6 | if (time.charAt(2) == ':') 7 | time = time.slice(0, 3) + '0' + time.slice(3); 8 | else 9 | time = '0' + time; 10 | } 11 | 12 | let new_time; 13 | if (time.slice(-2) === 'AM') { 14 | if (time.slice(0, 2) === '12') 15 | new_time = '00' + time.slice(2, 5); 16 | else 17 | new_time = time.slice(0, 5); 18 | } 19 | else { 20 | if (time.slice(0, 2) === '12') 21 | new_time = time.slice(0, 5); 22 | else { 23 | let hr = (Number(time.slice(0, 2)) + 12).toString(); 24 | new_time = hr + time.slice(2, 5); 25 | } 26 | } 27 | return new_time; 28 | } 29 | 30 | console.log(`Converted time: ${convertTo24HrsFormat(time)}`) 31 | -------------------------------------------------------------------------------- /Day-04/index2.js: -------------------------------------------------------------------------------- 1 | const time = '12:10AM'; 2 | 3 | function convertTo24HrsFormat(time) { 4 | let ss = ""; let x = ""; let k = 0; 5 | 6 | let l = time.length; 7 | for (let i = l - 1; i > 0; i--) { 8 | if (time.charAt(i) == ":") 9 | break; 10 | k++; 11 | } 12 | if (k == 3) 13 | time = time.substring(0, l - k) + "0" + time.substring(l - k, time.length); 14 | 15 | ss = time.substr(l - 2); 16 | if (ss === "AM") { 17 | if (Number(time.substring(0, 2)) == 12) { 18 | time = "00" + time.substring(2, l - 2); 19 | } 20 | else { 21 | time = "0" + time.substring(0, l - 2); 22 | } 23 | for (let i = l - 1; i > 0; i--) { 24 | if (time.charAt(i) == ":") 25 | break; 26 | k++; 27 | } 28 | if (k == 2) 29 | time = time.substring(0, l - k) + "0" + time.substring(l - k, time.length); 30 | return time; 31 | } 32 | 33 | else { 34 | if (time.substring(0, 2) === "12") { 35 | time = time.substring(0, 5); 36 | } 37 | else { 38 | x = time.substring(0, 2); 39 | x = Number(x); 40 | x = x + 12; 41 | time = x + time.substring(2, 5); 42 | } 43 | for (let i = l - 1; i > 0; i--) { 44 | if (time.charAt(i) == ":") 45 | break; 46 | k++; 47 | } 48 | if (k == 1) 49 | time = time.substring(0, l - k) + "0" + time.substring(l - k, time.length); 50 | return time; 51 | } 52 | } 53 | 54 | console.log(`Converted time: ${convertTo24HrsFormat(time)}`) 55 | -------------------------------------------------------------------------------- /Day-04/index3.js: -------------------------------------------------------------------------------- 1 | const time = '12:10AM'; 2 | 3 | function convertTo24HrsFormat(time) { 4 | // write your solution here 5 | if(time.length == 7){ 6 | var newTime = time.slice(0,5) 7 | var modifier = time.slice(-2); 8 | }else{ 9 | var newTime = time.slice(0,4) 10 | var modifier = time.slice(-2); 11 | } 12 | 13 | let [hours, minutes] = newTime.split(':'); 14 | if(hours.length == 1) hours = '0'+hours 15 | if(minutes.length == 1) minutes = '0'+minutes 16 | 17 | if (hours === '12') { 18 | hours = '00'; 19 | } 20 | 21 | if (modifier === 'PM') { 22 | hours = parseInt(hours, 10) + 12; 23 | } 24 | 25 | return `${hours}:${minutes}`; 26 | } 27 | 28 | console.log(`Converted time: ${convertTo24HrsFormat(time)}`) 29 | -------------------------------------------------------------------------------- /Day-05/README.md: -------------------------------------------------------------------------------- 1 | # Write a function which accepts a string argument and returns the count of characters between the first and last character 'X' 2 | * indexOf and lastIndexOf are the methods on String which returns the position of the given string in the input string from start and end respectively 3 | * If the match is not found, these methods return -1 4 | 5 | ## Challenges (0/4 done) 6 | * [ ] getTheGapX('XeroX') returns 4 7 | * [ ] getTheGapX('Xamarin') returns 0 8 | * [ ] getTheGapX('JavaScript') returns -1 9 | * [ ] getTheGapX("F(X) !== G(X) !== F(X)") returns 18 10 | 11 | ```js 12 | const str = 'XeroX'; 13 | 14 | function getTheGapX(str) { 15 | // write your solution here 16 | 17 | return 18 | } 19 | 20 | console.log(`Gap between the X's: ${getTheGapX(str)}`) 21 | ``` 22 | -------------------------------------------------------------------------------- /Day-05/index.js: -------------------------------------------------------------------------------- 1 | const str = 'XeroX'; 2 | 3 | function getTheGapX(str) { 4 | if( str.lastIndexOf('X')==-1&& str.indexOf('X')==-1) 5 | return -1; 6 | else 7 | return str.lastIndexOf('X') - str.indexOf('X'); 8 | } 9 | console.log(`Gap between the X's: ${getTheGapX(str)}`) 10 | -------------------------------------------------------------------------------- /Day-06/README.md: -------------------------------------------------------------------------------- 1 | # Write a function to truncate a string to a certain number of words 2 | * Truncate a string to a certain number of words 3 | 4 | ## Challenges (0/2 done) 5 | - [ ] truncateWithWordLimit("JavaScript is simple", 3) returns "JavaScript is simple" 6 | - [ ] truncateWithWordLimit("Codedamn is the best place to learn to code", 5) returns "Codedamn is the best place" 7 | 8 | ```js 9 | const str = 'JavaScript is simple but not easy to master'; 10 | const wordLimit = 3 11 | 12 | function truncateWithWordLimit(str, wordLimit) { 13 | // write your solution here 14 | 15 | return 16 | } 17 | 18 | console.log(`Truncated string: ${truncateWithWordLimit(str, wordLimit)}`) 19 | ``` 20 | -------------------------------------------------------------------------------- /Day-06/index.js: -------------------------------------------------------------------------------- 1 | const str = 'JavaScript is simple but not easy to master'; 2 | const wordLimit = 3 3 | 4 | function truncateWithWordLimit(str, wordLimit) { 5 | str = " " + str; let k = 0; let s = ""; 6 | for (let i = 0; i < str.length; i++) { 7 | if (str.charAt(i) == " ") 8 | k++; 9 | if (k > wordLimit) 10 | break; 11 | s = s + str.charAt(i); 12 | } 13 | return s.trim(); 14 | } 15 | 16 | console.log(`Truncated string: ${truncateWithWordLimit(str, wordLimit)}`) 17 | -------------------------------------------------------------------------------- /Day-07/README.md: -------------------------------------------------------------------------------- 1 | # Create a regular expression to validate if the given input is valid Indian mobile number or not 2 | * Regular expression check has to have an optional +91 or 0 in the beginning, then an optional space and 10 digits 3 | * `test` method of regular expression can be used to validate if the mobile number pattern matches or not 4 | 5 | ## Challenges (0/5 done) 6 | * [ ] validateMobile('+919876543210') returns true 7 | * [ ] validateMobile('+91 9876543210') returns true 8 | * [ ] validateMobile('09876543210') returns true 9 | * [ ] validateMobile('9876543210') returns true 10 | * [ ] validateMobile('99876543210') returns false 11 | 12 | ```js 13 | const number = '+919876543210'; 14 | 15 | function validateMobile(number) { 16 | // write your solution here 17 | 18 | return 19 | } 20 | 21 | console.log(`is a valid Indian mobile number: ${validateMobile(number)}`) 22 | ``` 23 | -------------------------------------------------------------------------------- /Day-07/index.js: -------------------------------------------------------------------------------- 1 | const number = '+919876543210'; 2 | 3 | function validateMobile(number) { 4 | let s=number+""; 5 | if(s.substring(0,3)==="+91"||s.charAt(0)==="0"||s.length==10) 6 | return true; 7 | else 8 | return false; 9 | } 10 | 11 | console.log(`is a valid Indian mobile number: ${validateMobile(number)}`) 12 | -------------------------------------------------------------------------------- /Day-08/README.md: -------------------------------------------------------------------------------- 1 | # Write a function which accepts two valid dates and returns the difference between them as number of days 2 | * The difference between 2 dates in JavaScript will give the time difference in milliseconds 3 | * Time difference can be converted in to days by dividing the 24Hrs time in milliseconds 4 | 5 | ## Challenges (0/3 done) 6 | * [ ] getDaysBetweenDates('10/15/2020', '12/1/2020') returns 47 7 | * [ ] getDaysBetweenDates('11/10/2021', '11/12/2021') returns 2 8 | * [ ] getDaysBetweenDates('11/01/2020', '11/05/2020') returns 4 9 | 10 | ```js 11 | const DAY_IN_MILLISECONDS = 1000 * 60 * 60 * 24; 12 | 13 | function getDaysBetweenDates(dateText1, dateText2) { 14 | // write your solution here 15 | 16 | return 17 | } 18 | 19 | console.log(`Days difference: ${getDaysBetweenDates('10/15/2020', '12/1/2020')}`) 20 | ``` 21 | -------------------------------------------------------------------------------- /Day-08/index.js: -------------------------------------------------------------------------------- 1 | const DAY_IN_MILLISECONDS = 1000 * 60 * 60 * 24; 2 | 3 | function getDaysBetweenDates(dateText1, dateText2) { 4 | var date1 = new Date(dateText1); 5 | var date2 = new Date(dateText2); 6 | var diff = Math.abs(date2 - date1); 7 | 8 | return(diff/DAY_IN_MILLISECONDS); 9 | } 10 | 11 | console.log(`Days difference: ${getDaysBetweenDates('10/15/2020', '12/1/2020')}`) 12 | -------------------------------------------------------------------------------- /Day-09/README.md: -------------------------------------------------------------------------------- 1 | # Write a function to check if an object is empty or not in javaScript? 2 | * How to check if an object is empty or not in javaScript? 3 | 4 | ## Challenges (0/2 done) 5 | * [ ] isEmpty({}) returns true 6 | * [ ] isEmpty({key: 1}) returns false 7 | 8 | ```js 9 | const obj = { key: 1 }; 10 | 11 | function isEmpty(obj) { 12 | // write your solution here 13 | 14 | return 15 | } 16 | 17 | console.log(`is empty object: ${isEmpty(obj)}`) 18 | ``` 19 | -------------------------------------------------------------------------------- /Day-09/index.js: -------------------------------------------------------------------------------- 1 | const obj = { key: 1 }; 2 | 3 | function isEmpty(obj) { 4 | return Object.entries(obj).length == 0; 5 | } 6 | 7 | console.log(`is empty object: ${isEmpty(obj)}`) 8 | -------------------------------------------------------------------------------- /Day-10/README.md: -------------------------------------------------------------------------------- 1 | # Write a function to remove array element based on object property? 2 | * How to remove array element based on object property? 3 | 4 | ## Challenges (0/3 done) 5 | * [ ] removeArrayElement("money") returns the array without the money object 6 | * [ ] removeArrayElement("id") returns the array without the id object 7 | * [ ] removeArrayElement("cStatus") returns the array without the cStatus object 8 | 9 | ```js 10 | const array = [ 11 | { field: "id", operator: "eq" }, 12 | { field: "cStatus", operator: "eq" }, 13 | { field: "money", operator: "eq" }, 14 | ]; 15 | 16 | const filterField = "money" 17 | 18 | function removeArrayElement(filterField) { 19 | // write your solution here 20 | 21 | return 22 | } 23 | 24 | console.log(`filtered array: ${removeArrayElement(filterField)}`) 25 | ``` 26 | -------------------------------------------------------------------------------- /Day-10/index.js: -------------------------------------------------------------------------------- 1 | const array = [ 2 | { field: "id", operator: "eq" }, 3 | { field: "cStatus", operator: "eq" }, 4 | { field: "money", operator: "eq" }, 5 | ]; 6 | 7 | const filterField = "money" 8 | 9 | function removeArrayElement(filterField) { 10 | // write your solution here 11 | var arr = array.filter(function (obj) { 12 | return obj.field !== filterField; 13 | }); 14 | 15 | return arr; 16 | } 17 | 18 | console.log(`filtered array: ${removeArrayElement(filterField)}`) 19 | -------------------------------------------------------------------------------- /Day-11/README.md: -------------------------------------------------------------------------------- 1 | # Return the N-th value of the Fibonacci sequence 2 | * Return the N-th value of the Fibonacci sequence 3 | 4 | ## Challenges (0/1 done) 5 | * [ ] function fibonacci(n) returns the N-th value of the Fibonacci sequence 6 | 7 | ```js 8 | function fibonacci(n) { 9 | // write your solution here 10 | 11 | return 12 | } 13 | 14 | console.log(`fibonacci value at position 5: ${fibonacci(5)}`) 15 | ``` 16 | -------------------------------------------------------------------------------- /Day-11/index.js: -------------------------------------------------------------------------------- 1 | function fibonacci(n) { 2 | if (n == 0) 3 | return 0; 4 | if (n <= 2) 5 | return 1; 6 | 7 | var a = 1, b = 1, c; 8 | for (var i = 3; i <= n; i++) { 9 | c = a + b; 10 | a = b; 11 | b = c; 12 | } 13 | return c; 14 | } 15 | console.log(`fibonacci value at position 5: ${fibonacci(5)}`) 16 | -------------------------------------------------------------------------------- /Day-12/README.md: -------------------------------------------------------------------------------- 1 | # Given a number from 0 to 999,999,999,999, spell out that number in English. 2 | 3 | ## Step 1: 4 | 5 | Handle the basic case of 0 through 99. 6 | 7 | If the input to the program is 22, then the output should be 'twenty-two'. 8 | 9 | Your program should complain loudly if given a number outside the blessed range. 10 | 11 | Some good test cases for this program are: 12 | 13 | * 0 14 | * 14 15 | * 50 16 | * 98 17 | * -1 18 | * 100 19 | 20 | ## Step 2: 21 | Implement breaking a number up into chunks of thousands. 22 | 23 | So 1234567890 should yield a list like 1, 234, 567, and 890, while the far simpler 1000 should yield just 1 and 0. 24 | 25 | The program must also report any values that are out of range. 26 | 27 | ## Step 3: 28 | Now handle inserting the appropriate scale word between those chunks. 29 | 30 | So 1234567890 should yield '1 billion 234 million 567 thousand 890' 31 | 32 | The program must also report any values that are out of range. It's fine to stop at "trillion". 33 | 34 | ## Step 4: 35 | Put it all together to get nothing but plain English. 36 | 37 | 12345 should give twelve thousand three hundred forty-five. 38 | 39 | The program must also report any values that are out of range. 40 | 41 | ## Challenges (0/2 done) 42 | * [ ] 14 becomes "fourteen". 43 | * [ ] 1323 becomes "one thousand three hundred twenty-three". 44 | 45 | ```js 46 | const sayNumberInEnglish = (n /* ADD MORE PARAMETERS IF NEEDED */) => { 47 | // Write your solution here 48 | return 49 | } 50 | 51 | console.log(`5635 in english is: ${sayNumberInEnglish(5635)}`) 52 | ``` 53 | -------------------------------------------------------------------------------- /Day-12/index.js: -------------------------------------------------------------------------------- 1 | const ones = [ 2 | "","one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", 3 | ]; 4 | const tens = [ 5 | "", "", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety", 6 | ]; 7 | const sep = [ 8 | "", " thousand ", " million ", " billion ", " trillion ", " quadrillion ", " quintillion ", " sextillion ", 9 | ]; 10 | 11 | const sayNumberInEnglish = (number) => { 12 | let arr = [], str = "", i = 0; 13 | if (number.length === 0) { 14 | return; 15 | } 16 | 17 | number = parseInt(number, 10); 18 | if (isNaN(number)) { 19 | return; 20 | } 21 | 22 | while(number){ 23 | arr.push(number%1000) 24 | number = parseInt(number/1000,10) 25 | } 26 | 27 | while(arr.length){ 28 | str = calc(arr.shift()) + sep[i++] + str; 29 | } 30 | 31 | return str; 32 | }; 33 | 34 | function calc (num) { 35 | let x = Math.floor(num/100); 36 | let y = Math.floor(num/10)%10 37 | let z = (num%10) 38 | let word = (x > 0 ? ones[x] + ' hundred ' : "") + (y >= 2 ? tens[y] + '-' + ones[z] : ones[10*y+z]) 39 | return word; 40 | } 41 | 42 | console.log(`5635 in english is: ${sayNumberInEnglish(5635)}`); 43 | -------------------------------------------------------------------------------- /Day-13/README.md: -------------------------------------------------------------------------------- 1 | # Convert given seconds to space age on all planets of our solar system 2 | 3 | ## Instructions 4 | 5 | **Given an age in seconds, calculate how old someone would be on:** 6 | 7 | - Mercury: orbital period 0.2408467 Earth years 8 | - Venus: orbital period 0.61519726 Earth years 9 | - Earth: orbital period 1.0 Earth years, 365.25 Earth days, or 31557600 seconds 10 | - Mars: orbital period 1.8808158 Earth years 11 | - Jupiter: orbital period 11.862615 Earth years 12 | - Saturn: orbital period 29.447498 Earth years 13 | - Uranus: orbital period 84.016846 Earth years 14 | - Neptune: orbital period 164.79132 Earth years 15 | 16 | **Pluto is not a planet** 17 | 18 | So if your function was called with 436575687 as the argument i.e spaceAge(436575687) it should return { "Mercury": 57.44, "Venus": 22.49, "Earth": 13.83, "Mars": 7.36, "Jupiter": 1.17, "Saturn": 0.47, "Uranus": 0.16, "Neptune": 0.08 } 19 | 20 | **IMPORTANT!!** 21 | 22 | - Your spaceAge function should return the (already given) yearsInAllPlanets object after setting age on each planet (each property of the object) 23 | 24 | - THE VALUE OF EACH PROPERTY SHOULD BE A NUMBER AND SHOULD HAVE MAXIMUM 2 DIGITS AFTER THE POINT example 4.34 25 | 26 | ## Challenges (0/2 done) 27 | - [ ] spaceAge(436575687) should return { "Mercury": 57.44, "Venus": 22.49, "Earth": 13.83, "Mars": 7.36, "Jupiter": 1.17, "Saturn": 0.47, "Uranus": 0.16, "Neptune": 0.08 } 28 | - [ ] spaceAge(65965561) should return { 'Mercury': 8.68 'Venus': 3.4 'Earth': 2.09 'Mars': 1.11 'Jupiter': 0.18 'Saturn': 0.07 'Uranus': 0.02 'Neptune': 0.01 } 29 | 30 | ```js 31 | const spaceAge = (seconds) => { 32 | const yearsInAllPlanets = { 33 | Mercury: 0, 34 | Venus: 0, 35 | Earth: 0, 36 | Mars: 0, 37 | Jupiter: 0, 38 | Saturn: 0, 39 | Uranus: 0, 40 | Neptune: 0, 41 | } 42 | 43 | // Your solution starts here 44 | 45 | // Your solution ends here 46 | 47 | return yearsInAllPlanets 48 | } 49 | 50 | console.log(spaceAge(Math.round(Math.random() * 99999999))) 51 | ``` 52 | -------------------------------------------------------------------------------- /Day-13/index.js: -------------------------------------------------------------------------------- 1 | const spaceAge = (seconds) => { 2 | const yearsInAllPlanets = { 3 | Mercury: 0, 4 | Venus: 0, 5 | Earth: 0, 6 | Mars: 0, 7 | Jupiter: 0, 8 | Saturn: 0, 9 | Uranus: 0, 10 | Neptune: 0, 11 | } 12 | 13 | // Your solution starts here 14 | const totalEarchSec = 31557600; 15 | seconds = parseFloat(seconds) 16 | yearsInAllPlanets.Mercury = parseFloat(((seconds/(totalEarchSec * 0.2408467))).toFixed(2)) 17 | yearsInAllPlanets.Venus = parseFloat((seconds/(totalEarchSec * 0.61519726)).toFixed(2)) 18 | yearsInAllPlanets.Earth = parseFloat((seconds/(totalEarchSec)).toFixed(2)) 19 | yearsInAllPlanets.Mars = parseFloat((seconds/(totalEarchSec * 1.8808158)).toFixed(2)) 20 | yearsInAllPlanets.Jupiter = parseFloat((seconds/(totalEarchSec * 11.862615)).toFixed(2)) 21 | yearsInAllPlanets.Saturn = parseFloat((seconds/(totalEarchSec * 29.447498)).toFixed(2)) 22 | yearsInAllPlanets.Uranus = parseFloat((seconds/(totalEarchSec * 84.016846)).toFixed(2)) 23 | yearsInAllPlanets.Neptune = parseFloat((seconds/(totalEarchSec * 164.79132)).toFixed(2)) 24 | // Your solution ends here 25 | 26 | return yearsInAllPlanets 27 | } 28 | 29 | console.log(spaceAge(Math.round(Math.random() * 99999999))) -------------------------------------------------------------------------------- /Day-14/README.md: -------------------------------------------------------------------------------- 1 | # Convert given array of digits of a base to another asked base 2 | 3 | ## Instructions 4 | 5 | - Convert a number, represented as a sequence of digits in one base, to any other base. 6 | - Implement general base conversion. Given a number in base a, represented as a sequence of digits, convert it to base b. 7 | 8 | ## Example 9 | 10 | - input: convertDigitsToAskedBase([5, 8], 10, 16) 11 | - output: [3, 10] 12 | 13 | **convertDigitsToAskedBase([5, 8], 10, 16) is passed to the convertDigitsToAskedBase function i.e 58 in base 10 as [5, 8] in array is passed and asked to convert to base 16 which is 310. This should be returned in array as [3, 10].** 14 | 15 | ## Note 16 | - [3, 10] is not other than [3, 10] is because 3 and 10 both are valid digits of base 16 17 | - [3, 1, 0] is WRONG because even though 1 and 0 are valid digits of base 16 it can be represented as 10 without taking the 3rd place. 18 | 19 | ## Challenges (0/2 done) 20 | - [ ] convertDigitsToAskedBase([5, 8], 10, 16) should return [3, 10] 21 | - [ ] convertDigitsToAskedBase() with any random value passed should return correct array as asked 22 | 23 | ```js 24 | /** 25 | * 26 | * @param {number[]} digits Array of valid digits of baseA 27 | * @param {number} baseA base a 28 | * @param {number} baseB base b in which digits are to be converted 29 | * @returns {number[]} Array of valid digits of baseB 30 | */ 31 | const convertDigitsToAskedBase = (digits, baseA, baseB) => { 32 | // Your code here 33 | 34 | return 35 | } 36 | ``` 37 | -------------------------------------------------------------------------------- /Day-14/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @param {number[]} digits Array of valid digits of baseA 4 | * @param {number} baseA base a 5 | * @param {number} baseB base b in which digits are to be converted 6 | * @returns {number[]} Array of valid digits of baseB 7 | */ 8 | const convertToIntialBase = (digits,baseA) => { 9 | return parseInt(digits.join('',baseA)) 10 | } 11 | const convertToFinalBase = (digit,baseB) => { 12 | return digit.toString(baseB) 13 | } 14 | const convertDigitsToAskedBase = (digits, baseA, baseB) => { 15 | // Your code here 16 | let num = convertToIntialBase(digits,baseA) 17 | num = convertToFinalBase(num,baseB) 18 | num = num.split('') 19 | for(let i=0;i { 15 | // Code here 16 | 17 | return 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /Day-15/index.js: -------------------------------------------------------------------------------- 1 | const isPangram = (input) => { 2 | input = input.toUpperCase().split('') 3 | for(let i=65; i<91; i++){ 4 | let char = String.fromCharCode(i); 5 | if(input.includes(char)) continue; 6 | else return false; 7 | } 8 | return true; 9 | } 10 | 11 | 12 | console.log(isPangram('The quick brown fox jumps over the lazy dog.')) 13 | -------------------------------------------------------------------------------- /Day-16/README.md: -------------------------------------------------------------------------------- 1 | # Ask the Bob 2 | 3 | ## Instructions 4 | 5 | - Bob is a lackadaisical teenager. In conversation, his responses are very limited. 6 | - Bob answers 'Sure.' if you ask him a question, such as "How are you?". 7 | - He answers 'Whoa, chill out!' if you YELL AT HIM (in all capitals). 8 | - He answers 'Calm down, I know what I'm doing!' if you yell a question at him. 9 | - He says 'Fine. Be that way!' if you address him without actually saying anything. 10 | - He answers 'Whatever.' to anything else. 11 | - Bob's conversational partner is a purist when it comes to written communication and always follows normal rules regarding sentence punctuation in English. 12 | 13 | ## Challenges (0/2 done) 14 | - [ ] Any random string will be passed, it should work as asked 15 | - [ ] Any random string will be passed, it should work as asked 16 | 17 | ```js 18 | function hey(message) { 19 | // Code here 20 | 21 | return 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /Day-16/index.js: -------------------------------------------------------------------------------- 1 | 2 | const isUpper = (string) => { 3 | return !/[a-z]/.test(string) && /[A-Z]/.test(string) 4 | } 5 | 6 | function hey(message) { 7 | // Code here 8 | let pureLetterString = "" 9 | message.split("").forEach(character => { 10 | if(/[a-zA-Z]/.test(character)){ 11 | pureLetterString += character 12 | } 13 | }) 14 | 15 | console.log(pureLetterString); 16 | 17 | if(isUpper(pureLetterString) && message.trim().charAt(message.length-1) === '?'){ 18 | return "Calm down, I know what I'm doing!" 19 | } 20 | else if(isUpper(pureLetterString)){ 21 | return "Whoa, chill out!" 22 | } 23 | else if(message.trim().charAt(message.length-1) === '?'){ 24 | return "Sure." 25 | } 26 | else if(message === ""){ 27 | return "Fine. Be that way!" 28 | } 29 | 30 | return "Whatever." 31 | } 32 | 33 | function hey1(message) { 34 | 35 | let pureLetterString = "" 36 | message.split("").forEach(character => { 37 | if(/[a-zA-Z]/.test(character)){ 38 | pureLetterString += character 39 | } 40 | }) 41 | console.log(pureLetterString); 42 | if(pureLetterString == pureLetterString.toUpperCase() && message.slice(-1) === '?') return "Calm down, I know what I'm doing!"; 43 | else if(pureLetterString == pureLetterString.toUpperCase()) return 'Whoa, chill out!'; 44 | else if(message.slice(-1) == '?') return "Sure"; 45 | else if(message === "") return 'Fine. Be that way!'; 46 | return 'Whatever.' 47 | } 48 | 49 | 50 | console.log(hey('HASDFASDF ASDF23423 ASDF ?')); -------------------------------------------------------------------------------- /Day-17/README.md: -------------------------------------------------------------------------------- 1 | # Longest Consecutive Sequence 2 | 3 | - Given an array of elements, find a subsequence in the array such that all the elements in the sequence are consecutive irrespective of their order. 4 | 5 | ## Example 6 | 7 | - Input: [100,4,200,1,3,2] 8 | 9 | - Output: 4 // LCS [1, 2, 3, 4] 10 | 11 | ## Conceptually this is how it should work. 12 | - Copy all the elements of the array in a set. Iterate the array and in each iteration determine if the current element will lead to new subsequence by checking if there is no element less than the current, present in the set. 13 | 14 | - Then find how long this subsequence can be by incrementing the count till there is consecutive elements in the set. In the end return the longest consecutive sequence. 15 | 16 | ## Challenges (0/2 done) 17 | - [ ] longestConsecutiveSequence([100,4,200,1,3,2]) returns 4 18 | - [ ] longestConsecutiveSequence([0,3,7,2,5,8,4,6,0,1]) returns 9 19 | 20 | ```js 21 | /** 22 | * 23 | * @param {number[]} inputArray Array of numbers 24 | */ 25 | const longestConsecutiveSequence = (inputArray) => { 26 | // Your code here 27 | 28 | return 29 | } 30 | ``` 31 | -------------------------------------------------------------------------------- /Day-17/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * @param {number[]} inputArray Array of numbers 4 | */ 5 | const longestConsecutiveSequence = (inputArray) => { 6 | let sortedArr = inputArray.sort(function(a, b){return a-b}); 7 | let currSeq = 0; 8 | let maxSeq = 0; 9 | mySet = new Set([...sortedArr]) 10 | sortedArr = [...mySet] 11 | if(sortedArr.length === 0) return 0; 12 | for(let i=0;i { 22 | // Code here 23 | 24 | return 25 | } 26 | 27 | const grainsOn = (input) => { 28 | // Code here 29 | 30 | return 31 | } 32 | 33 | console.log(`Grains on 5th square: ${grainsOn(5)}`) 34 | console.log(`Total grains on the Chess Board: ${totalGrains()}`) 35 | ``` 36 | -------------------------------------------------------------------------------- /Day-18/index.js: -------------------------------------------------------------------------------- 1 | const totalGrains = () => { 2 | // Code here 3 | let startingPoint = 0 4 | let totalGrains = BigInt(0) 5 | while(startingPoint < 64){ 6 | totalGrains += BigInt(2**startingPoint) 7 | startingPoint++ 8 | } 9 | return totalGrains; 10 | } 11 | 12 | const grainsOn = (input) => { 13 | // Code here 14 | return BigInt(2**(input-1)) 15 | } 16 | 17 | console.log(`Grains on 5th square: ${grainsOn(5)}`) 18 | console.log(`Total grains upto 5th square: ${totalGrains()}`) -------------------------------------------------------------------------------- /Day-19/README.md: -------------------------------------------------------------------------------- 1 | # Resistor Color map 2 | 3 | ## Instruction 4 | 5 | ◆ If you want to build something using a Raspberry Pi, you'll probably use resistors. For this exercise, you need to know two things about them: 6 | - Each resistor has a resistance value. 7 | - Resistors are small - so small in fact that if you printed the resistance value on them, it would be hard to read. 8 | 9 | ◆ To get around this problem, manufacturers print color-coded bands onto the resistors to denote their resistance values. Each band has a position and a numeric value. 10 | 11 | ◆ The first 2 bands of a resistor have a simple encoding scheme: each color maps to a single number. 12 | 13 | ◆ In this exercise you are going to create a helpful program so that you don't have to remember the values of the bands. 14 | 15 | ◆ These colors are encoded as follows: 16 | 17 | - Black: 0\ 18 | - Brown: 1\ 19 | - Red: 2\ 20 | - Orange: 3\ 21 | - Yellow: 4\ 22 | - Green: 5\ 23 | - Blue: 6\ 24 | - Violet: 7\ 25 | - Grey: 8\ 26 | - White: 9 27 | 28 | ◆ The goal of this exercise is to create a way: 29 | - to look up the numerical value associated with a particular color band 30 | - to list the different band colors 31 | 32 | ◆ Mnemonics map the colors to the numbers, that, when stored as an array, happen to map to their index in the array: Better Be Right Or Your Great Big Values Go Wrong. 33 | 34 | ## NOTE 35 | - Although the color names are capitalised in the description, the function colorCode will always be called with the lowercase equivalent, e.g brown instead of Brown. 36 | 37 | ## Challenges (0/2 done) 38 | - [ ] colorCode('blue') should return 6 39 | - [ ] colorCode('white') should return 9 40 | 41 | ```js 42 | const colorCode = (color) => { 43 | // Code here 44 | 45 | return 46 | } 47 | ``` 48 | -------------------------------------------------------------------------------- /Day-19/index.js: -------------------------------------------------------------------------------- 1 | const colorCode = (color) => { 2 | color = color.toLowerCase(); 3 | switch(color){ 4 | case 'brown' : return 1; 5 | case 'red' : return 2; 6 | case 'yellow' : return 4; 7 | case 'green' : return 5; 8 | case 'blue' : return 6; 9 | case 'violet' : return 7; 10 | case 'grey' : return 8; 11 | case 'white' : return 9; 12 | default : return 0; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Day-20/README.md: -------------------------------------------------------------------------------- 1 | # Add two numbers 2 | 3 | ## Instruction 4 | - Add two numbers 5 | 6 | ## Challenges (0/2 done) 7 | - [ ] add Two Numbers 8 | - [ ] JUST ADD TWO NUMBERS! YAAAY 9 | 10 | ```js 11 | const addTwoNumbers = (a, b) => { 12 | // code here 13 | 14 | return 15 | } 16 | 17 | ``` 18 | -------------------------------------------------------------------------------- /Day-20/index.js: -------------------------------------------------------------------------------- 1 | const addTwoNumbers = (a, b) => { 2 | // code here 3 | return a+b; 4 | } -------------------------------------------------------------------------------- /Day-21/README.md: -------------------------------------------------------------------------------- 1 | # Union of Two Arrays 2 | 3 | ## Instruction 4 | - Write the code for the function which returns the the union of the two given arrays 5 | 6 | ## Challenges (0/2 done) 7 | - [ ] unionOfArrays(['a','b','c'],['a',1,2,'d']) should return ['a','b','c',1,2,'d'] 8 | - [ ] unionOfArrays(['array','object'],['value','object','key']) should return ['array','object', 'value', 'key'] 9 | - [ ] unionOfArrays([1, 2, 34, 45, 3], [3, 24, 21]) == [1,2,34,45,3,24,21]) should return [1,2,34,45,3,24,21] 10 | 11 | ```js 12 | const unionOfArrays = (arr1, arr2) => { 13 | // code below here 14 | 15 | return; 16 | }; 17 | 18 | console.log(`The union is ${unionOfArrays([1, 2, 34, 45, 3], [3, 24, 21])}`); 19 | ``` 20 | -------------------------------------------------------------------------------- /Day-21/index.js: -------------------------------------------------------------------------------- 1 | const unionOfArrays = (arr1, arr2) => { 2 | // code below here 3 | let union = [...new Set([...arr1,...arr2])] 4 | return union; 5 | }; 6 | 7 | console.log(`The union is ${unionOfArrays([1, 2, 34, 45, 3], [3, 24, 21])}`);\ -------------------------------------------------------------------------------- /Day-22/README.md: -------------------------------------------------------------------------------- 1 | # Unique In Order 2 | 3 | ## Instruction 4 | - Implement the function unique_in_order which takes as argument a sequence and returns a list of items without any elements with the same value next to each other and preserving the original order of elements. 5 | - The argument can contain a string or an array 6 | - For example: 7 | - uniqueInOrder([1,2,2,3,3]) should return [1,2,3] 8 | - uniqueInOrder('ABBCcAD') should return ['A', 'B', 'C', 'c', 'A', 'D'] 9 | 10 | ## Challenges (0/3 done) 11 | - [ ] uniqueInOrder('AAAABBBCCDAABBB') should return ['A', 'B', 'C', 'D', 'A', 'B'] 12 | - [ ] uniqueInOrder('ABBCcAD') should return ['A', 'B', 'C', 'c', 'A', 'D'] 13 | - [ ] uniqueInOrder([1,2,2,3,3]) should return [1,2,3] 14 | 15 | ```js 16 | let uniqueInOrder = (iterable) => { 17 | //your code here - remember iterable can be a string or an array 18 | }; 19 | ``` 20 | -------------------------------------------------------------------------------- /Day-22/index.js: -------------------------------------------------------------------------------- 1 | let uniqueInOrder = (iterable) => { 2 | //your code here - remember iterable can be a string or an array 3 | const type = typeof iterable 4 | if(type == 'string') iterable = iterable.split('') 5 | let stack = []; 6 | stack.push(iterable[0]) 7 | for(let i=0;i 0 && temp.unshift(digit*multiplier) 9 | multiplier *= 10 10 | } 11 | return temp.join('+') 12 | } 13 | 14 | console.log(expandedForm(734)); 15 | -------------------------------------------------------------------------------- /Day-25/README.md: -------------------------------------------------------------------------------- 1 | # Stop gninnipS My sdroW! 2 | 3 | ## Instruction 4 | - Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present. 5 | 6 | - Examples: spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw" spinWords( "This is a test") => returns "This is a test" spinWords( "This is another test" )=> returns "This is rehtona test" 7 | 8 | ## Challenges (0/3 done) 9 | - [ ] spinWords("Hey fellow warriors") should return"Hey wollef sroirraw" 10 | - [ ] spinWords("You are almost to the last test") should return "You are tsomla to the last test" 11 | - [ ] expandedForm(734) should return '700+30+4' 12 | 13 | ```js 14 | function spinWords(str) { 15 | //TODO Have fun :) 16 | } 17 | ``` 18 | -------------------------------------------------------------------------------- /Day-25/index.js: -------------------------------------------------------------------------------- 1 | function spinWords(str) { 2 | //TODO Have fun :) 3 | let strSplit = str.split(" "); 4 | 5 | for(let i = 0; i < strSplit.length; i++) { 6 | if(strSplit[i].length >= 5) { 7 | let rev = reverseString(strSplit[i]); 8 | strSplit[i] = rev; 9 | } 10 | } 11 | 12 | return strSplit.join(" "); 13 | 14 | } 15 | 16 | function reverseString(str) { 17 | return str.split('').reverse().join(''); 18 | } 19 | -------------------------------------------------------------------------------- /Day-26/README.md: -------------------------------------------------------------------------------- 1 | # Find the odd int 2 | 3 | ## Instruction 4 | - Given an array of integers, find the one that appears an odd number of times. 5 | - There will always be only one integer that appears an odd number of times. 6 | - For example: 7 | - [7] should return 7, because it occurs 1 time (which is odd). [0] should return 0, because it occurs 1 time (which is odd). [1,1,2] should return 2, because it occurs 1 time (which is odd). [0,1,0,1,0] should return 0, because it occurs 3 times (which is odd). [1,2,2,3,3,3,4,3,3,3,2,2,1] should return 4, because it appears 1 time (which is odd). 8 | 9 | ## Challenges (0/3 done) 10 | - [ ] findOdd([20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5]) should return 5 11 | - [ ] findOdd([1,1,1,1,1,1,10,1,1,1,1]) should return 10 12 | - [ ] findOdd([5,4,3,2,1,5,4,3,2,10,10]) should return 1 13 | 14 | ```js 15 | function findOdd(arr) { 16 | //happy coding! 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /Day-26/index.js: -------------------------------------------------------------------------------- 1 | function findOdd(arr) { 2 | //happy coding! 3 | arr = arr.sort((a, b) => a-b); 4 | let obj = createObj(arr); 5 | //console.log(obj); 6 | 7 | for(let key in obj) { 8 | if(obj[key]%2 !== 0) { 9 | return parseInt(key); 10 | } 11 | } 12 | return 0; 13 | } 14 | 15 | function createObj(ar) { 16 | let obj = {}; 17 | 18 | for(let i=0; i0) { 9 | temp += strChar[i]; 10 | k--; 11 | } 12 | temp = capitalFirstLetter(temp); 13 | res += `${temp}-` 14 | } 15 | 16 | return res.slice(0, -1); 17 | } 18 | 19 | 20 | function capitalFirstLetter(str) { 21 | return str.charAt(0).toUpperCase() + str.slice(1); 22 | } 23 | -------------------------------------------------------------------------------- /Day-30/README.md: -------------------------------------------------------------------------------- 1 | # Mexican Wave 2 | 3 | ## Instructions 4 | - The wave (known as the Mexican wave in the English-speaking world outside North America) is an example of metachronal rhythm achieved in a packed stadium when successive groups of spectators briefly stand, yell, and raise their arms. Immediately upon stretching to full height, the spectator returns to the usual seated position. 5 | - The result is a wave of standing spectators that travels through the crowd, even though individual spectators never move away from their seats. In many large arenas the crowd is seated in a contiguous circuit all the way around the sport field, and so the wave is able to travel continuously around the arena; in discontiguous seating arrangements, the wave can instead reflect back and forth through the crowd. When the gap in seating is narrow, the wave can sometimes pass through it. Usually only one wave crest will be present at any given time in an arena, although simultaneous, counter-rotating waves have been produced. (Source Wikipedia) 6 | 7 | ### Task 8 | To create a function that turns a string into a Mexican Wave. You will be passed a string and you must return that string in an array where an uppercase letter is a person standing up. 9 | 10 | ### Rules 11 | - The input string will always be lower case but maybe empty. 12 | - If the character in the string is whitespace then pass over it as if it was an empty seat 13 | 14 | ### Example 15 | wave("hello") returns the array ["Hello", "hEllo", "heLlo", "helLo", "hellO"] 16 | 17 | 18 | ## Challenges (0/3) done 19 | - [ ] `wave("hello")` should return `["Hello", "hEllo", "heLlo", "helLo", "hellO"]` 20 | - [ ] `wave("two words")` should return `["Two words", "tWo words", "twO words", "two Words", "two wOrds", "two woRds", "two worDs", "two wordS"]` 21 | - [ ] `wave(" gap ")` should return `[" Gap ", " gAp ", " gaP "]` 22 | 23 | ```js 24 | function wave(str) { 25 | // Your Code goes below 26 | 27 | } 28 | 29 | console.log(wave("two words")); 30 | 31 | 32 | ``` 33 | -------------------------------------------------------------------------------- /Day-30/index.js: -------------------------------------------------------------------------------- 1 | function wave(str) { 2 | // Your Code goes below 3 | 4 | let result = []; 5 | for(let i = 0; i < str.length; i++) { 6 | let strChar = str.toLowerCase().split(""); 7 | if(strChar[i] === ' ') { 8 | continue; 9 | } else { 10 | strChar[i] = strChar[i].toUpperCase(); 11 | result.push(strChar.join("")); 12 | } 13 | 14 | } 15 | return result; 16 | } 17 | 18 | console.log(wave("two words")); 19 | -------------------------------------------------------------------------------- /Day-31/README.md: -------------------------------------------------------------------------------- 1 | # Write a Program to Find the Factorial of a Number 2 | 3 | # Instructions 4 | - The factorial of a number is the product of all the numbers from 1 to that number. 5 | - Example: factorial of 5 is equal to 1 * 2 * 3 * 4 * 5 = 120. 6 | - The factorial of a positive number n is given by: 7 | factorial of n (n!) = 1 * 2 * 3 * 4.....n The factorial of negative numbers do not exist and the factorial of 0 is 1. 8 | 9 | # Challenges (0/3)done 10 | - [ ] factorial(2) is 2 11 | - [ ] factorial(5) is 120 12 | - [ ] factorial(10) is 3628800 13 | 14 | ```js 15 | function factorial(n) { 16 | // write your code here 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /Day-31/index.js: -------------------------------------------------------------------------------- 1 | function factorial(n) { 2 | // write your code here 3 | if(n == 0) 4 | return 1; 5 | return n*factorial(n-1); 6 | } 7 | -------------------------------------------------------------------------------- /Day-32/README.md: -------------------------------------------------------------------------------- 1 | # Write a program to find the greatest common divisor (gcd) of two positive numbers 2 | 3 | ## Instruction 4 | - The greatest common divisor (GCD), also called the greatest common factor, of two numbers is the largest number that divides them both. For instance, the greatest common factor of 20 and 15 is 5, since 5 divides both 20 and 15 and no larger number has this property. 5 | 6 | ## Challenges (0/3 done) 7 | - [ ] gcd(2154, 458) 8 | - [ ] gcd(12, 4) 9 | - [ ] gcd(333, 3333) 10 | 11 | ```js 12 | function gcd(a, b) { 13 | // write your code here 14 | return 15 | } 16 | 17 | const a = 2154 18 | const b = 458 19 | 20 | console.log("The GCD of " + a + " ", b + " is " + gcd(a, b)); 21 | ``` 22 | -------------------------------------------------------------------------------- /Day-32/index.js: -------------------------------------------------------------------------------- 1 | function gcd(a, b) { 2 | // write your code here 3 | if(b==0) return a; 4 | return gcd(b,a%b) 5 | } 6 | 7 | const a = 2154 8 | const b = 458 9 | 10 | console.log("The GCD of " + a + " ", b + " is " + gcd(a, b)); -------------------------------------------------------------------------------- /Day-33/README.md: -------------------------------------------------------------------------------- 1 | # Write a program to print unique values from an array 2 | 3 | ## Instructions 4 | 5 | - Input : const arrOfNum = [1, 2, 2, 4, 5, 6, 6] 6 | - Output : [1, 2, 4, 5, 6] 7 | 8 | ## Challenges (0/2 done) 9 | - [ ] set([1, 2, 2, 4, 5, 6, 6]) returns [1, 2, 4, 5, 6] 10 | - [ ] set([1, 1, 1, 1, 1]) returns [1] 11 | 12 | ```js 13 | function set(arrOfNum) { 14 | // write your code here 15 | return 16 | } 17 | 18 | const arrOfNum = [1, 2, 2, 4, 5, 6, 6]; 19 | 20 | console.log("result is + " + set(arrOfNum)); 21 | } 22 | ``` 23 | -------------------------------------------------------------------------------- /Day-33/index.js: -------------------------------------------------------------------------------- 1 | function set(arrOfNum) { 2 | // write your code here 3 | let arr = arrOfNum.filter((ele,index) => arrOfNum.indexOf(ele) === index) 4 | return arr 5 | } 6 | 7 | const arrOfNum = [1, 2, 2, 4, 5, 6, 6]; 8 | 9 | console.log("result is + " + set(arrOfNum)); -------------------------------------------------------------------------------- /Day-34/README.md: -------------------------------------------------------------------------------- 1 | # Write a program to find the most frequent item of an array 2 | 3 | ## Instructions 4 | 5 | - Input : const arr = [3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3]; 6 | - Output : a 5 7 | 8 | ## Challenges (0/2 done) 9 | - [ ] mostFreq([1, 2, 2, 4, 5, 6, 6]) returns 2 2 10 | - [ ] mostFreq([3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3]) returns a 5 11 | 12 | ```js 13 | function mostFreq(arr) { 14 | // write your code here 15 | return 16 | } 17 | 18 | const arr = [1, 2, 2, 4, 5, 6, 6]; 19 | 20 | console.log(mostFreq(arr)); 21 | ``` 22 | -------------------------------------------------------------------------------- /Day-34/index.js: -------------------------------------------------------------------------------- 1 | function mostFreq(arr) { 2 | // write your code here 3 | let maxCount = 0; 4 | let mapArr = new Map() 5 | const unique = arr.filter((ele,index) => arr.indexOf(ele) === index) 6 | 7 | for(let i=0;i1){ 13 | maxCount = Math.max(maxCount,count) 14 | mapArr.set(unique[i],maxCount) 15 | } 16 | } 17 | const result = [...mapArr.entries()].reduce((a, e ) => e[1] > a[1] ? e : a) 18 | return result.join(' ') 19 | } 20 | 21 | const arr = [3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3]; 22 | 23 | console.log(mostFreq(arr)); -------------------------------------------------------------------------------- /Day-35/README.md: -------------------------------------------------------------------------------- 1 | # Write a JavaScript function to get nth largest element from an unsorted array 2 | 3 | - Given an array of elements, find a subsequence in the array such that all the elements in the sequence are consecutive irrespective of their order. 4 | 5 | ## Example 6 | 7 | - Input : nthlargest([ 43, 56, 23, 89, 88, 90, 99, 652], 4) 8 | - Output : 89 9 | 10 | ## Challenges (0/2 done) 11 | - [ ] nthlargest([ 43, 56, 23, 89, 88, 90, 99, 652], 4) returns 89 12 | - [ ] nthlargest([ 10, 100, 1000, 10000], 2) returns 1000 13 | 14 | ```js 15 | function nthlargest(arr, highest) { 16 | // write your code here 17 | return 18 | } 19 | 20 | const arr = [43, 56, 23, 89, 88, 90, 99, 652]; 21 | const highest = 4; 22 | 23 | console.log(nthlargest(arr, highest)); 24 | ``` 25 | -------------------------------------------------------------------------------- /Day-35/index.js: -------------------------------------------------------------------------------- 1 | function nthlargest(arr, highest) { 2 | // write your code here 3 | arr.sort((a,b) => a-b) 4 | return arr[arr.length-highest] 5 | } 6 | 7 | const arr = [43, 56, 23, 89, 88, 90, 99, 652]; 8 | const highest = 4; 9 | 10 | console.log(nthlargest(arr, highest)); -------------------------------------------------------------------------------- /Day-36/README.md: -------------------------------------------------------------------------------- 1 | # Rna Transcription 2 | 3 | ## Instructions 4 | - Given a DNA strand, return its RNA complement (per RNA transcription). 5 | - Both DNA and RNA strands are a sequence of nucleotides. 6 | - The four nucleotides found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T). 7 | - The four nucleotides found in RNA are adenine (A), cytosine (C), guanine (G) and uracil (U). 8 | - Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement: 9 | - G -> C 10 | - C -> G 11 | - T -> A 12 | - A -> U 13 | 14 | ## Challenges (0/2 done) 15 | - [ ] transcription('GCT') should return 'CGA' 16 | - [ ] transcription('GATC') should return 'CUAG' 17 | 18 | ```js 19 | const transcription = (dna) => { 20 | // code here 21 | 22 | return 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /Day-36/index.js: -------------------------------------------------------------------------------- 1 | const transcription = (dna) => { 2 | // code here 3 | let rna = '' 4 | for(let i=0;i { 16 | // code here 17 | 18 | return 19 | } 20 | ``` 21 | -------------------------------------------------------------------------------- /Day-37/index.js: -------------------------------------------------------------------------------- 1 | const isLeap = (year) => { 2 | // code here 3 | return ((year%4 === 0 && year%100 !== 0) || year%400===0) 4 | } 5 | -------------------------------------------------------------------------------- /Day-38/README.md: -------------------------------------------------------------------------------- 1 | # Luhn algorithm 2 | 3 | ## Instructions 4 | 5 | - Given a number determine whether or not it is valid per the Luhn formula. 6 | - The Luhn algorithm is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers and Canadian Social Insurance Numbers. 7 | - The task is to check if a given string is valid. 8 | 9 | ## Validating a Number 10 | - Strings of length 1 or less are not valid. Spaces are allowed in the input, but they should be stripped before checking. All other non-digit characters are disallowed. 11 | 12 | ## Example 1: valid credit card number 13 | - 4539 3195 0343 6467 14 | - The first step of the Luhn algorithm is to double every second digit, starting from the right. We will be doubling 15 | - 4_3_ 3_9_ 0_4_ 6_6_ 16 | - If doubling the number results in a number greater than 9 then subtract 9 from the product. The results of our doubling: 17 | - 8569 6195 0383 3437 18 | - Then sum all of the digits: 19 | - 8+5+6+9+6+1+9+5+0+3+8+3+3+4+3+7 = 80 20 | - If the sum is evenly divisible by 10, then the number is valid. This number is valid! 21 | 22 | ## Example 2: invalid credit card number 23 | - 8273 1232 7352 0569 24 | - Double the second digits, starting from the right 25 | - 7253 2262 5312 0539 26 | - Sum the digits 27 | - 7+2+5+3+2+2+6+2+5+3+1+2+0+5+3+9 = 57 28 | - 57 is not evenly divisible by 10, so this number is not valid. 29 | 30 | ## Challenges (0/2 done) 31 | - [ ] valid(string) should return true or false accordingly 32 | - [ ] valid(string) should return true or false accordingly 33 | 34 | ```js 35 | const valid = (string) => { 36 | // code here 37 | 38 | return 39 | } 40 | ``` 41 | -------------------------------------------------------------------------------- /Day-38/index.js: -------------------------------------------------------------------------------- 1 | const valid = (string) => { 2 | // code here 3 | string = string.replace(/\s/g, '') 4 | if(string.length <= 1) return false; 5 | if(isNaN(string)) return false; 6 | let digit=1; 7 | let arr = []; 8 | for(let i=string.length-1;i>=0;i--){ 9 | if(digit%2==0){ 10 | let val = parseInt(string[i])*2 11 | if(val > 9) val -= 9 12 | arr.push(val) 13 | } 14 | else arr.push(parseInt(string[i])) 15 | digit++ 16 | } 17 | const sum = arr.reduce((acc,val) => acc + val,0) 18 | return sum%10 === 0; 19 | } 20 | 21 | console.log(valid('4539 3195 0343 6467')); -------------------------------------------------------------------------------- /Day-39/README.md: -------------------------------------------------------------------------------- 1 | # Mixed Juices 2 | 3 | - Given an array of elements, find a subsequence in the array such that all the elements in the sequence are consecutive irrespective of their order. 4 | 5 | ## Instructions 6 | 7 | - Your friend Li Mei runs her own juice bar where she sells delicious mixed fruit juices. You are a frequent customer in her shop and realized you could make your friend's life easier. You decide to use your coding skills to help Li Mei with her job. 8 | 9 | ## 1. Determine how long it takes to mix a juice 10 | - Li Mei likes to tell her customers in advance how long they have to wait for a juice from the menu that they ordered. She has a hard time remembering the exact numbers, because the time it takes to mix the juices varies. 'Pure Strawberry Joy' takes 0.5 minutes, 'Energizer' and 'Green Garden' take 1.5 minutes each, 'Tropical Island' takes 3 minutes and 'All or Nothing' takes 5 minutes. For all other drinks (e.g., special offers) you can assume a preparation time of 2.5 minutes. 11 | 12 | - To help your friend, write a function timeToMixJuice that takes a juice from the menu as an argument and returns the number of minutes it take to mix that drink. 13 | 14 | ``` 15 | timeToMixJuice('Tropical Island'); // => 3 16 | 17 | timeToMixJuice('Berries & Lime'); // => 2.5 18 | ``` 19 | 20 | ## 2. Replenish the lime wedge supply 21 | - A lot of Li Mei's creations include lime wedges, either as an ingredient or as part of the decoration. So when she starts her shift in the morning she needs to make sure the bin of lime wedges is full for the day ahead. 22 | 23 | - Implement the function limesToCut which takes the number of lime wedges Li Mei needs to cut and an array representing the supply of whole limes she has at hand. She can get 6 wedges from a 'small' lime, 8 wedges from a 'medium' lime and 10 from a 'large' lime. She always cuts the limes in the order in which they appear in the list, starting with the first item. She keeps going until she reached the number of wedges that she needs or until she runs out of limes. 24 | 25 | - Li Mei would like to know in advance how many limes she needs to cut. The limesToCut function should return the number of limes to cut. 26 | 27 | - limesToCut(25, ['small', 'small', 'large', 'medium', 'small']); // => 4 28 | 29 | ## 3. Finish up the shift 30 | - Li Mei always works until 3pm. Then her employee Dmitry takes over. There are often drinks that have been ordered but are not prepared yet when Li Mei's shift ends. Dmitry will then prepare the remaining juices. 31 | 32 | - To make the hand-over easier, implement a function remainingOrders which takes the number of minutes left in Li Mei's shift and an array of juices that have been ordered but not prepared yet. The function should return the orders that Li Mei cannot start preparing before the end of her work day. 33 | 34 | - The time left in the shift will always be greater than 0. Furthermore the orders are prepared in the order in which they appear in the array. If Li Mei starts to mix a certain juice, she will always finish it even if she has to work a bit longer. If there are no remaining orders left that Dmitry needs to take care of, an empty array should be returned. 35 | 36 | - remainingOrders(5, ['Energizer', 'All or Nothing', 'Green Garden']); // => ['Green Garden'] 37 | 38 | ## Challenges (0/2 done) 39 | - [ ] function timeToMixJuice(name) should return asked values 40 | - [ ] function limesToCut(wedgesNeeded, limes) should return asked values 41 | - [ ] function remainingOrders(timeLeft, orders) should return asked values 42 | 43 | ```js 44 | const timeToMixJuice = (name) => { 45 | // code here 46 | 47 | return 48 | } 49 | 50 | const limesToCut = (wedgesNeeded, limes) => { 51 | // code here 52 | 53 | return 54 | } 55 | 56 | const remainingOrders = (timeLeft, orders) => { 57 | // code here 58 | 59 | return 60 | } 61 | ``` 62 | -------------------------------------------------------------------------------- /Day-39/index.js: -------------------------------------------------------------------------------- 1 | const timeToMixJuice = (name) => { 2 | // code here 3 | switch(name){ 4 | case 'Pure Strawberry Joy' : return 0.5 5 | case 'Energizer': return 1.5; 6 | case 'Green Garden': return 1.5; 7 | case 'Tropical Island': return 3; 8 | case 'All or Nothing': return 5; 9 | default: return 2.5; 10 | } 11 | } 12 | 13 | const limesToCut = (wedgesNeeded, limes) => { 14 | // code here 15 | let totalWedge = 0 16 | let count = 0 17 | for(i=0;i= wedgesNeeded) break; 23 | } 24 | return count 25 | } 26 | 27 | const remainingOrders = (timeLeft, orders) => { 28 | // code here 29 | let newTime = 0; 30 | for(i=0;i true 15 | 16 | needsLicense('bike'); // => false 17 | ``` 18 | 19 | ## 2. Choose between two potential vehicles to buy 20 | - You evaluate your options of available vehicles. You manage to narrow it down to two options but you need help making the final decision. For that implement the function chooseVehicle(option1, option2) that takes two vehicles as arguments and returns a decision that includes the option that comes first in dictionary order. 21 | 22 | ``` 23 | chooseVehicle('Wuling Hongguang', 'Toyota Corolla'); // => 'Toyota Corolla is clearly the better choice.' 24 | 25 | chooseVehicle('Volkswagen Beetle', 'Volkswagen Golf'); // => 'Volkswagen Beetle is clearly the better choice.' 26 | ``` 27 | 28 | ## 3. Calculate an estimation for the price of a used vehicle 29 | - Now that you made your decision you want to make sure you get a fair price at the dealership. Since you are interested in buying a used vehicle, the price depends on how old the vehicle is. For a rough estimate, assume if the vehicle is less than 3 years old, it costs 80% of the original price it had when it was brand new. If it is more than 10 years old, it costs 50%. If the vehicle is at least 3 years old but not older than 10 years, it costs 70% of the original price. 30 | 31 | - Implement the calculateResellPrice(originalPrice, age) function that applies this logic using if, else if and else (there are other ways but you want to practice). It takes the original price and the age of the vehicle as arguments and returns the estimated price in the dealership. 32 | 33 | ``` 34 | calculateResellPrice(1000, 1); // => 800 35 | 36 | calculateResellPrice(1000, 5); // => 700 37 | 38 | calculateResellPrice(1000, 15); // => 500 39 | ``` 40 | 41 | ## Challenges (0/2 done) 42 | - [ ] needsLicense(kind) should work as asked 43 | - [ ] chooseVehicle(option1, option2) should work as asked 44 | - [ ] calculateResellPrice(originalPrice, age) should work as asked 45 | 46 | ```js 47 | const needsLicense = (kind) => { 48 | // code here 49 | 50 | return 51 | } 52 | 53 | const chooseVehicle = (option1, option2) => { 54 | // code here 55 | 56 | return 57 | } 58 | 59 | const calculateResellPrice = (originalPrice, age) => { 60 | // code here 61 | 62 | return 63 | } 64 | ``` 65 | -------------------------------------------------------------------------------- /Day-40/index.js: -------------------------------------------------------------------------------- 1 | const needsLicense = (kind) => { 2 | // code here 3 | switch(kind){ 4 | case 'car': return true; 5 | case 'truck': return true; 6 | default: return false; 7 | } 8 | } 9 | 10 | const chooseVehicle = (option1, option2) => { 11 | // code here 12 | return `${ option1.charCodeAt(0) >= option2.charCodeAt(0) ? option1 : option2 } is clearly the better choice.`; 13 | } 14 | 15 | const calculateResellPrice = (originalPrice, age) => { 16 | // code here 17 | let discount = 0; 18 | if(age < 3) discount = 80 19 | else if (age >= 3 && age < 10) discount = 70 20 | else discount = 50 21 | return (originalPrice * discount)/100; 22 | } 23 | 24 | console.log(chooseVehicle('Volkswagen Beetle', 'Volkswagen Golf')); 25 | -------------------------------------------------------------------------------- /Day-41/README.md: -------------------------------------------------------------------------------- 1 | # Categorize New Member 2 | 3 | ## Instructions 4 | - The Western Suburbs Croquet Club has two categories of membership, Senior and Open. They would like your help with an application form that will tell prospective members which category they will be placed. 5 | - To be a senior, a member must be at least 55 years old and have a handicap greater than 7. In this croquet club, handicaps range from -2 to +26; the better the player the lower the handicap. 6 | 7 | ## Input 8 | - Input will consist of a array of pairs. Each pair contains information for a single potential member. Information consists of an integer for the person's age and an integer for the person's handicap. 9 | 10 | ## Output 11 | - Output will consist of a list of string values stating whether the respective member is to be placed in the senior or open category. 12 | 13 | ## Example 14 | - (openOrSenior([[45, 12],[55,21],[19, -2],[104, 20]]) returns ['Open', 'Senior', 'Open', 'Senior'] 15 | 16 | ## Challenges (0/2 done) 17 | - [ ] openOrSenior([[45, 12],[55,21],[19, -2],[104, 20]]) should return ['Open', 'Senior', 'Open', 'Senior'] 18 | - [ ] openOrSenior([[3, 12],[55,1],[91, -2],[53, 23]]) should return['Open', 'Open', 'Open', 'Open'] 19 | - [ ] openOrSenior([[59, 12],[55,-1],[12, -2],[12, 12]]) should return ['Senior', 'Open', 'Open', 'Open']) 20 | 21 | ```js 22 | function openOrSenior(data) { 23 | // your code goes below 24 | } 25 | 26 | let output = openOrSenior([ 27 | [45, 12], 28 | [55, 21], 29 | [19, -2], 30 | [104, 20], 31 | ]); 32 | 33 | console.log(output); 34 | ``` 35 | -------------------------------------------------------------------------------- /Day-41/index.js: -------------------------------------------------------------------------------- 1 | function openOrSenior(data) { 2 | // your code goes below 3 | return data.map((member) => { 4 | return member[0] >= 55 && member[1] > 7 ? "Senior" : "Open"; 5 | }) 6 | } 7 | 8 | let output = openOrSenior([ 9 | [[3, 12],[55,1],[91, -2],[53, 23]] 10 | ]); 11 | 12 | console.log(output); 13 | -------------------------------------------------------------------------------- /Day-42/README.md: -------------------------------------------------------------------------------- 1 | # Sum of two lowest positive integers 2 | 3 | ## Instructions 4 | 5 | - Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 positive integers. No floats or non-positive integers will be passed. 6 | - For example, when an array is passed like [19, 5, 42, 2, 77], the output should be 7. 7 | 8 | ## Challenges (0/2 done) 9 | - [ ] sumTwoSmallestNumbers([5, 8, 12, 19, 22]) should return 13 10 | - [ ] sumTwoSmallestNumbers([15, 28, 4, 2, 43]) should return 6 11 | - [ ] sumTwoSmallestNumbers([23, 71, 33, 82, 1]) should return 24 12 | 13 | ```js 14 | function sumTwoSmallestNumbers(numbers) { 15 | //Code below 16 | } 17 | ``` 18 | -------------------------------------------------------------------------------- /Day-42/index.js: -------------------------------------------------------------------------------- 1 | function sumTwoSmallestNumbers(numbers) { 2 | //Code below 3 | numbers.sort((a,b)=>a-b) 4 | return numbers[0]+numbers[1] 5 | } 6 | console.log( sumTwoSmallestNumbers([19, 5, 42, 2, 77])); -------------------------------------------------------------------------------- /Day-43/README.md: -------------------------------------------------------------------------------- 1 | # Highest Scoring Word 2 | 3 | ## Instructions 4 | - Given a string of words, you need to find the highest scoring word. 5 | - Each letter of a word scores points according to its position in the alphabet: a = 1, b = 2, c = 3 etc. 6 | - You need to return the highest scoring word as a string. 7 | - If two words score the same, return the word that appears earliest in the original string. 8 | - All letters will be lowercase and all inputs will be valid. 9 | 10 | Chanllenges (0/2) done 11 | - [ ] high('man i need a taxi up to ubud') should return 'taxi' 12 | - [ ] high('what time are we climbing up the volcano') should return 'volcano' 13 | 14 | ```js 15 | function high(str) { 16 | // code here 17 | } 18 | 19 | ``` 20 | -------------------------------------------------------------------------------- /Day-43/index.js: -------------------------------------------------------------------------------- 1 | 2 | const alphabetValue = { 3 | 'a': 1, 4 | 'b': 2, 5 | 'c': 3, 6 | 'd': 4, 7 | 'e': 5, 8 | 'f': 6, 9 | 'g': 7, 10 | 'h': 8, 11 | 'i': 9, 12 | 'j': 10, 13 | 'k': 11, 14 | 'l': 12, 15 | 'm': 13, 16 | 'n': 14, 17 | 'o': 15, 18 | 'p': 16, 19 | 'q': 17, 20 | 'r': 18, 21 | 's': 19, 22 | 't': 20, 23 | 'u': 21, 24 | 'v': 22, 25 | 'w': 23, 26 | 'x': 24, 27 | 'y': 25, 28 | 'z': 26, 29 | } 30 | 31 | 32 | function high(str) { 33 | let strArr = str.split(" "); 34 | let maxCnt = 0; 35 | let result = strArr[0]; 36 | strArr.forEach(item => { 37 | let currCnt = getSumOfWord(item) 38 | if(maxCnt < currCnt) { 39 | maxCnt = currCnt; 40 | result = item; 41 | } 42 | }) 43 | 44 | return result; 45 | } 46 | 47 | function getSumOfWord(word) { 48 | word = word.split(''); 49 | let sum = 0; 50 | word.forEach(item => { 51 | sum += alphabetValue[item]; 52 | }) 53 | 54 | return sum; 55 | } 56 | -------------------------------------------------------------------------------- /Day-43/index1.js: -------------------------------------------------------------------------------- 1 | function high(x) { 2 | //code your magic here 3 | x = x.split(' ') 4 | let theWord = '' 5 | let max = 0; 6 | x.map((ele) => { 7 | let score = 0 8 | for(let i=0;i max) { 11 | max = score 12 | theWord = ele 13 | } 14 | } 15 | }) 16 | return theWord 17 | } 18 | console.log(high('what time are we climbing up the volcano')); 19 | -------------------------------------------------------------------------------- /Day-44/README.md: -------------------------------------------------------------------------------- 1 | # Count the divisors of a number 2 | 3 | ## Instructions 4 | 5 | - Count the number of divisors of a positive integer n. 6 | - Examples (input --> output) 7 | 8 | ``` 9 | 4 --> 3 (1, 2, 4) 10 | 5 --> 2 (1, 5) 11 | 12 --> 6 (1, 2, 3, 4, 6, 12) 12 | 30 --> 8 (1, 2, 3, 5, 6, 10, 15, 30) 13 | ``` 14 | 15 | ## Challenges (0/2 done) 16 | - [ ] getDivisorsCnt(10) should return 4 17 | - [ ] getDivisorsCnt(11) should return 2 18 | - [ ] getDivisorsCnt(54) should return 8 19 | 20 | ```js 21 | function getDivisorsCnt(num) { 22 | // code below 23 | } 24 | ``` 25 | -------------------------------------------------------------------------------- /Day-44/index.js: -------------------------------------------------------------------------------- 1 | function getDivisorsCnt(num) { 2 | // code below 3 | let arr = [] 4 | for(let i=1;i<=num;i++){ 5 | if(num%i==0) arr.push(i) 6 | } 7 | return arr.length; 8 | } 9 | console.log(getDivisorsCnt(10)); 10 | -------------------------------------------------------------------------------- /Day-45/README.md: -------------------------------------------------------------------------------- 1 | # Find The Parity Outlier 2 | 3 | ## Instructions 4 | - You are given an array (which will have a length of at least 3, but could be very large) containing integers. 5 | - The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. 6 | - Write a method that takes the array as an argument and returns this "outlier" N. 7 | 8 | ## Examples 9 | - [2, 4, 0, 100, 4, 11, 2602, 36] Should return: 11 (the only odd number) 10 | 11 | - [160, 3, 1719, 19, 11, 13, -21] Should return: 160 (the only even number) 12 | 13 | ## Challenges (0/3 done) 14 | - [ ] findOutlier([2,6,8,10,3]) should return 3 15 | - [ ] findOutlier([0,0,3,0,0]) should return 3 16 | - [ ] findOutlier([1,1,0,1,1]) should return 0 17 | 18 | ```js 19 | function findOutlier(integers) { 20 | //your code here 21 | } 22 | ``` 23 | -------------------------------------------------------------------------------- /Day-45/index.js: -------------------------------------------------------------------------------- 1 | function findOutlier(integers) { 2 | //your code here 3 | let evenArr = [] 4 | let oddArr = []; 5 | integers.map((ele) => { 6 | if(ele%2===0)evenArr.push(ele) 7 | else oddArr.push(ele) 8 | }) 9 | if(oddArr.length > evenArr.length) return evenArr[0] 10 | else return oddArr[0] 11 | } 12 | console.log(findOutlier([0,0,3,0,0])); 13 | -------------------------------------------------------------------------------- /Day-46/README.md: -------------------------------------------------------------------------------- 1 | # A Needle in the Haystack 2 | 3 | ## Instructions 4 | - Write a function findNeedle() that takes an array full of junk but containing one "needle" 5 | - After your function finds the needle it should return a message (as a string) that says: "found the needle at position " plus the index it found the needle, so: 6 | findNeedle(['hay', 'junk', 'hay', 'hay', 'moreJunk', 'needle', 'randomJunk']) should return "found the needle at position 5" 7 | 8 | ## Examples 9 | - [2, 4, 0, 100, 4, 11, 2602, 36] Should return: 11 (the only odd number) 10 | 11 | - [160, 3, 1719, 19, 11, 13, -21] Should return: 160 (the only even number) 12 | 13 | ## Challenges (0/3 done) 14 | - [ ] findNeedle(['3', '123124234', undefined, 'needle', 'world', 'hay', 2, '3', true, false]) should return 'found the needle at position 3' 15 | - [ ] findNeedle(['283497238987234', 'a dog', 'a cat', 'some random junk', 'a piece of hay', 'needle', 'something somebody lost a while ago']) should return 'found the needle at position 5' 16 | - [ ] findNeedle([1,2,3,4,5,6,7,8,8,7,5,4,3,4,5,6,67,5,5,3,3,4,2,34,234,23,4,234,324,324,'needle',1,2,3,4,5,5,6,5,4,32,3,45,54]) should return 'found the needle at position 30' 17 | 18 | ```js 19 | function findNeedle(haystack) { 20 | //your code here 21 | return 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /Day-46/index.js: -------------------------------------------------------------------------------- 1 | function findNeedle(haystack) { 2 | // your code here 3 | let foundAt = 0; 4 | haystack.forEach((ele,index) => { 5 | if(ele == 'needle'){ 6 | foundAt = index 7 | return; 8 | } 9 | }) 10 | return `found the needle at position ${foundAt}` 11 | } -------------------------------------------------------------------------------- /Day-47/README.md: -------------------------------------------------------------------------------- 1 | # Isograms 2 | 3 | ## Instructions 4 | An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case. 5 | 6 | ## Examples 7 | - "Dermatoglyphics" --> true 8 | - "aba" --> false 9 | - "moOse" --> false (ignore letter case) 10 | 11 | ## Note : An empty string is also an isogram 12 | 13 | ## Challenges (0/3 done) 14 | - [ ] sIsogram("isogram") should return true 15 | - [ ] isIsogram("") should return true 16 | - [ ] isIsogram("moOse") should return false 17 | 18 | ```js 19 | function isIsogram(str) { 20 | // your code here 21 | } 22 | ``` 23 | -------------------------------------------------------------------------------- /Day-47/index.js: -------------------------------------------------------------------------------- 1 | function isIsogram(str) { 2 | // your code here 3 | let unique = [...new Set(str.toLowerCase().split(''))]; 4 | return unique.length === str.length ? true : false 5 | } -------------------------------------------------------------------------------- /Day-48/README.md: -------------------------------------------------------------------------------- 1 | # Human readable duration format 2 | 3 | ## Instructions 4 | - Your task is to write a function which formats a duration, given as a number of seconds, in a human-friendly way. 5 | - The function must accept a non-negative integer. If it is zero, it just returns "now". Otherwise, the duration is expressed as a combination of years, days, hours, minutes and seconds. 6 | - It is much easier to understand with an example: 7 | ``` 8 | formatDuration(62) // returns "1 minute and 2 seconds" 9 | formatDuration(3662) // returns "1 hour, 1 minute and 2 seconds" 10 | ``` 11 | - For the purpose of this challenge, a year is 365 days and a day is 24 hours. 12 | 13 | ## Note that spaces are important. 14 | 15 | ## Detailed rules 16 | 17 | - The resulting expression is made of components like 4 seconds, 1 year, etc. In general, a positive integer and one of the valid units of time, separated by a space. The unit of time is used in plural if the integer is greater than 1. 18 | - The components are separated by a comma and a space (", "). Except the last component, which is separated by " and ", just like it would be written in English. 19 | - A more significant units of time will occur before than a least significant one. Therefore, 1 second and 1 year is not correct, but 1 year and 1 second is. 20 | - Different components have different unit of times. So there is not repeated units like in 5 seconds and 1 second. 21 | - A component will not appear at all if its value happens to be zero. Hence, 1 minute and 0 seconds is not valid, but it should be just 1 minute. 22 | - A unit of time must be used "as much as possible". It means that the function should not return 61 seconds, but 1 minute and 1 second instead. Formally, the duration specified by of a component must not be greater than any valid more significant unit of time. 23 | 24 | ## Challenges (0/3 done) 25 | - [ ] formatDuration(1) should return "1 second" 26 | - [ ] formatDuration(3662) should return "1 hour, 1 minute and 2 seconds" 27 | - [ ] formatDuration(62) should return "1 minute and 2 seconds" 28 | 29 | ```js 30 | function formatDuration(seconds) { 31 | // your code here 32 | } 33 | ``` 34 | -------------------------------------------------------------------------------- /Day-48/index.js: -------------------------------------------------------------------------------- 1 | function formatDuration(seconds) { 2 | // your code here 3 | let time = { year:3153600, day: 86400, hour: 3600, minute: 60, second: 1 }; 4 | let arr = []; 5 | if(seconds === 0) return 'now' 6 | if(seconds < 0) return; 7 | 8 | for(let key in time){ 9 | if(seconds >= time[key]){ 10 | var val = Math.floor(seconds/time[key]); 11 | val += val > 1 ? ' '+ key + 's' : ' ' + key 12 | arr.push(val) 13 | seconds = seconds%time[key] 14 | } 15 | } 16 | return arr.length > 1 ? arr.join(', ').replace(/,([^,]*)$/,' and'+'$1') : arr[0] 17 | 18 | } -------------------------------------------------------------------------------- /Day-49/README.md: -------------------------------------------------------------------------------- 1 | # Is this a triangle? 2 | 3 | ## Instructions 4 | - Implement a function that accepts 3 integer values a, b, c. The function should return true if a triangle can be built with the sides of given length and false in any other case. 5 | - (In this case, all triangles must have surface greater than 0 to be accepted). 6 | - Hint You can check whether the sum of the two sides of a triangle is greater than the third side in all possible combinations. 7 | 8 | ## Challenges (0/3 done) 9 | - [ ] isTriangle(1,2,2) should return true 10 | - [ ] isTriangle(7,2,2) should return false 11 | - [ ] isTriangle(7,14,16) should return true 12 | 13 | ```js 14 | function isTriangle(a, b, c) { 15 | // your code here 16 | } 17 | ``` 18 | -------------------------------------------------------------------------------- /Day-49/index.js: -------------------------------------------------------------------------------- 1 | function isTriangle(a, b, c) { 2 | // your code here 3 | return a+b>c && b+c>a && c+a>b 4 | } 5 | console.log(isTriangle(7,2,2)); -------------------------------------------------------------------------------- /Day-50/README.md: -------------------------------------------------------------------------------- 1 | # Get the Middle Character 2 | 3 | ## Instructions 4 | - You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters. 5 | 6 | ``` 7 | Kata.getMiddle("test") should return "es" 8 | 9 | Kata.getMiddle("testing") should return "t" 10 | 11 | Kata.getMiddle("middle") should return "dd" 12 | 13 | Kata.getMiddle("A") should return "A" 14 | ``` 15 | 16 | ## Challenges (0/3 done) 17 | - [ ] getMiddle("testing") should return "t" 18 | - [ ] getMiddle("middle") should return "dd" 19 | - [ ] getMiddle("A") should return "A" 20 | 21 | ```js 22 | function getMiddle(s) { 23 | // your code here 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /Day-50/index.js: -------------------------------------------------------------------------------- 1 | function getMiddle(s) { 2 | // your code here 3 | const n = s.length 4 | const mid = Math.floor(n/2) 5 | if(n==1) return s 6 | if(n%2!=0) return s[mid] 7 | else return s.slice(mid-1,mid+1) 8 | } 9 | 10 | console.log(getMiddle("testing")); -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Pranay Gupta 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 50-Days-of-JavaScript 2 | Solutions to 50 Days of JavaScript! by [Codedamn](https://codedamn.com/) 3 | 4 |
5 | 50 days of JS banner 6 |
7 | 8 | ## Challenge List: 9 | 1. Function which returns a random number in the given range 10 | 1. Write a program to reverse a string 11 | --------------------------------------------------------------------------------