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 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)); 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