From 87a1b958b5b7269930edb5464f2ef7a40d4bc092 Mon Sep 17 00:00:00 2001 From: gshettylee Date: Sat, 1 May 2021 16:34:19 +0530 Subject: [PATCH 1/4] Revert "Commiting Just the Python directory" This reverts commit a772f93d73e434a6c286044e939c8b35c82ab320. --- Javascript/TruncateString.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Javascript/TruncateString.js diff --git a/Javascript/TruncateString.js b/Javascript/TruncateString.js new file mode 100644 index 0000000..4fc5d97 --- /dev/null +++ b/Javascript/TruncateString.js @@ -0,0 +1,15 @@ +// Truncate the string to given num of charcaters and add "..." at the end of the new string +// +//First Git Hub commit + + +function truncateString(str, num) { + // Clear out that junk in your trunk + if (str.length > num) { + return str.slice(0, num) + "..."; + } else { + return str; + } +} + +console.log(truncateString("A-tisket a-tasket A green and yellow basket", 8)); From 19edb70dfc92d586df0f51f223f7ced35cd93b94 Mon Sep 17 00:00:00 2001 From: gshettylee Date: Mon, 3 May 2021 22:59:35 +0530 Subject: [PATCH 2/4] Checking in new scripts --- Javascript/2ndStringContainsallelement.js | 20 ++++++++++++++++++++ Javascript/Splitarraytothesizeofarray.js | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Javascript/2ndStringContainsallelement.js create mode 100644 Javascript/Splitarraytothesizeofarray.js diff --git a/Javascript/2ndStringContainsallelement.js b/Javascript/2ndStringContainsallelement.js new file mode 100644 index 0000000..0b313dc --- /dev/null +++ b/Javascript/2ndStringContainsallelement.js @@ -0,0 +1,20 @@ +/*Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array. + +For example, ["hello", "Hello"], should return true because all of the letters in the second string are present in the first, ignoring case. + +The arguments ["hello", "hey"] should return false because the string hello does not contain a y. +*/ + +function mutation(arr) { + let test = arr[1].toLowerCase().split(''); + //console.log(test) + let target = arr[0].toLowerCase().split(''); + for (let i = 0; i < test.length; i++) { + if (target.indexOf(test[i]) < 0) { + return false; + } + } + return true +} + +console.log(mutation(["hello", "Hell"])); \ No newline at end of file diff --git a/Javascript/Splitarraytothesizeofarray.js b/Javascript/Splitarraytothesizeofarray.js new file mode 100644 index 0000000..edadbc8 --- /dev/null +++ b/Javascript/Splitarraytothesizeofarray.js @@ -0,0 +1,18 @@ +/* +Write a function that splits an array (first argument) into groups the length + of size (second argument) and returns them as a two-dimensional array. + + chunkArrayInGroups(["a", "b", "c", "d"], 2) should return [["a", "b"], ["c", "d"]]. +chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3) should return [[0, 1, 2], [3, 4, 5], [6]]. +*/ + +function chunkArrayInGroups(arr, size) { + let arr2= [] + for (let i=0 ; i< arr.length; i+=size){ + let arr1 = arr.slice(i,i+size) + arr2.push(arr1) + } + return arr2; + } + + console.log(chunkArrayInGroups(["a", "b", "c", "d"], 2)); \ No newline at end of file From 64409930a400f696feee13f00a13baa48f8ee6d3 Mon Sep 17 00:00:00 2001 From: gshettylee Date: Fri, 28 May 2021 12:18:55 +0530 Subject: [PATCH 3/4] CHecking in FCC exercise script --- Javascript/largestinnestedarray.js | 20 +++++++++++++++++++ Javascript/palindromecheckerusingregex.js | 18 +++++++++++++++++ Javascript/romannumbers.js | 24 +++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 Javascript/largestinnestedarray.js create mode 100644 Javascript/palindromecheckerusingregex.js create mode 100644 Javascript/romannumbers.js diff --git a/Javascript/largestinnestedarray.js b/Javascript/largestinnestedarray.js new file mode 100644 index 0000000..af672bf --- /dev/null +++ b/Javascript/largestinnestedarray.js @@ -0,0 +1,20 @@ +/* +Largest of the each element in nested array +*/ + +function largestOfFour(arr) { + let results = []; + for (let i = 0; i < arr.length; i++) { + let largestNumber = arr[i][0]; + for (let j = 1; j < arr[i].length; j++) { + if (arr[i][j] > largestNumber) { + largestNumber = arr[i][j]; + } + } + results.push(largestNumber); + } + + return results; + } + + console.log(largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]])); \ No newline at end of file diff --git a/Javascript/palindromecheckerusingregex.js b/Javascript/palindromecheckerusingregex.js new file mode 100644 index 0000000..8597ab2 --- /dev/null +++ b/Javascript/palindromecheckerusingregex.js @@ -0,0 +1,18 @@ +function palindrome(str) { + str = str.toLowerCase().trim() + str = str.replace(/[-&\/\\#,_ +()$~%.'":*?<>{}]/g, ''); + console.log(str) + newstr = "" + for (let i=0; i 3999){ + return num + } + else{ + while (num>0){ + let div = Math.floor (num /val[i]) + num = num % val[i] + while (div){ + roman += symb[i] + div = div -1 + } + i+=1 + } + return roman; + } + } + + romnum = convertToRoman(36); + console.log(romnum) \ No newline at end of file From db0c5a46b4c4fd1384de3e1aa5c5a44dc7c4f944 Mon Sep 17 00:00:00 2001 From: gshettylee Date: Fri, 28 May 2021 13:53:43 +0530 Subject: [PATCH 4/4] Adding the regex phone number validator script --- Javascript/regexToMatchThePhoneNumber.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Javascript/regexToMatchThePhoneNumber.js diff --git a/Javascript/regexToMatchThePhoneNumber.js b/Javascript/regexToMatchThePhoneNumber.js new file mode 100644 index 0000000..9d5fa48 --- /dev/null +++ b/Javascript/regexToMatchThePhoneNumber.js @@ -0,0 +1,23 @@ +/* +Validate the phone number if it finds a match return true else false + +555-555-5555 +(555)555-5555 +(555) 555-5555 +555 555 5555 +5555555555 +1 555 555 5555 + +*/ + +function telephoneCheck(str) { + let regex = /^1?\s?(\([\d+]{3}\)[- ]?|[\d+]{3}[- ]?)[0-9]{3}[- ]?[\d+]{4}$/ + val = regex.test(str) + // To find the string match + val1 = str.match(regex) + console.log(val1) + return val + +} + + console.log(telephoneCheck("555-555-5555")) \ No newline at end of file