From 4b42899a451129be668c60e750c48b3963070495 Mon Sep 17 00:00:00 2001 From: Kaio Rosa Date: Mon, 11 Mar 2019 14:45:10 -0300 Subject: [PATCH] add some fcc challenges --- Basic Algorithm Scripting/chunky-monkey.json | 1 + Basic Algorithm Scripting/confirm-the-ending.json | 1 + Basic Algorithm Scripting/falsy-bouncer.json | 1 + Basic Algorithm Scripting/finders-keepers.json | 1 + Basic Algorithm Scripting/mutations.json | 1 + Basic Algorithm Scripting/repeat-a-string-repeat-a-string.json | 1 + Basic Algorithm Scripting/return-largest-numbers-in-arrays.json | 1 + Basic Algorithm Scripting/slice-and-splice.json | 1 + Basic Algorithm Scripting/title-case-a-sentence.json | 1 + Basic Algorithm Scripting/truncate-a-string.json | 1 + Basic Algorithm Scripting/where-do-i-belong.json | 1 + Intermediate Algorithm Scripting/diff-two-arrays.json | 1 + Intermediate Algorithm Scripting/seek-and-destroy.json | 1 + Intermediate Algorithm Scripting/sum-all-numbers-in-a-range.json | 1 + 14 files changed, 14 insertions(+) create mode 100644 Basic Algorithm Scripting/chunky-monkey.json create mode 100644 Basic Algorithm Scripting/confirm-the-ending.json create mode 100644 Basic Algorithm Scripting/falsy-bouncer.json create mode 100644 Basic Algorithm Scripting/finders-keepers.json create mode 100644 Basic Algorithm Scripting/mutations.json create mode 100644 Basic Algorithm Scripting/repeat-a-string-repeat-a-string.json create mode 100644 Basic Algorithm Scripting/return-largest-numbers-in-arrays.json create mode 100644 Basic Algorithm Scripting/slice-and-splice.json create mode 100644 Basic Algorithm Scripting/title-case-a-sentence.json create mode 100644 Basic Algorithm Scripting/truncate-a-string.json create mode 100644 Basic Algorithm Scripting/where-do-i-belong.json create mode 100644 Intermediate Algorithm Scripting/diff-two-arrays.json create mode 100644 Intermediate Algorithm Scripting/seek-and-destroy.json create mode 100644 Intermediate Algorithm Scripting/sum-all-numbers-in-a-range.json diff --git a/Basic Algorithm Scripting/chunky-monkey.json b/Basic Algorithm Scripting/chunky-monkey.json new file mode 100644 index 0000000..ab771d9 --- /dev/null +++ b/Basic Algorithm Scripting/chunky-monkey.json @@ -0,0 +1 @@ +{"index.js":"function chunkArrayInGroups(arr, size) {\n // Break it up.\n // create an empty array to store the subarrays\n let newArray = [];\n // divide the array into size chunks and push it into the newArray\n for(let i =0; i < arr.length; i+= size){\n newArray.push(arr.slice(i,i+size));\n }\n return newArray;\n}\n\nchunkArrayInGroups([\"a\", \"b\", \"c\", \"d\"], 3);"} \ No newline at end of file diff --git a/Basic Algorithm Scripting/confirm-the-ending.json b/Basic Algorithm Scripting/confirm-the-ending.json new file mode 100644 index 0000000..5dff59b --- /dev/null +++ b/Basic Algorithm Scripting/confirm-the-ending.json @@ -0,0 +1 @@ +{"index.js":"function confirmEnding(str, target) {\n // \"Never give up and good luck will find you.\"\n // -- Falco\n str = str.split('');\n target = target.split('');\n let targetLen = target.length;\n let startLooking = str.length - targetLen;\n \n for(let i =0; i < targetLen; i++){\n if(str[startLooking] !== target[i]){\n return false;\n }\n startLooking++;\n }\n return true;\n}\n\nconsole.log(confirmEnding(\"Bastian\", \"n\"));"} \ No newline at end of file diff --git a/Basic Algorithm Scripting/falsy-bouncer.json b/Basic Algorithm Scripting/falsy-bouncer.json new file mode 100644 index 0000000..3b1a684 --- /dev/null +++ b/Basic Algorithm Scripting/falsy-bouncer.json @@ -0,0 +1 @@ +{"index.js":"function bouncer(arr) {\n // Don't show a false ID to this bouncer.\n\n // converting the array to its boolean values\n for(let i = 0; i < arr.length; i++){\n if(Boolean(arr[i]) === false){\n arr.splice(i,1);\n i--;// this is to compensate the element taken out\n }\n }\n \n \n return arr;\n}\n\nconsole.log(bouncer([7, \"ate\", \"\", false, 9]));"} \ No newline at end of file diff --git a/Basic Algorithm Scripting/finders-keepers.json b/Basic Algorithm Scripting/finders-keepers.json new file mode 100644 index 0000000..25369eb --- /dev/null +++ b/Basic Algorithm Scripting/finders-keepers.json @@ -0,0 +1 @@ +{"index.js":"function findElement(arr, func) {\n // loops through an array and check the func\n for(let i =0; i < arr.length; i++){\n if(func(arr[i]) === true){\n return arr[i];\n }\n }\n return undefined;\n}\n\nfindElement([1, 3, 5, 8, 9, 10], num => num % 2 === 0);"} \ No newline at end of file diff --git a/Basic Algorithm Scripting/mutations.json b/Basic Algorithm Scripting/mutations.json new file mode 100644 index 0000000..7ac089c --- /dev/null +++ b/Basic Algorithm Scripting/mutations.json @@ -0,0 +1 @@ +{"index.js":"function mutation(arr) {\n // to lower case all the strings\n for(let i =0; i < arr.length; i++){\n arr[i] = arr[i].toLowerCase();\n }\n //turn the strings into arrays\n let firstString = arr[0].split('');\n let secondString = arr[1].split('');\n // loop through the second string and looking for matches\n for(let j = 0; j < secondString.length ; j++){\n // if we don't find any occurence of the letters \n //in the second string in the first we return false\n if(firstString.indexOf(secondString[j]) === -1){\n return false;\n }\n }\n // if we looped through and any of them returned -1 all of the letters are in the first string\n return true;\n}\n\nmutation([\"HeLlo\", \"hey\"]);"} \ No newline at end of file diff --git a/Basic Algorithm Scripting/repeat-a-string-repeat-a-string.json b/Basic Algorithm Scripting/repeat-a-string-repeat-a-string.json new file mode 100644 index 0000000..defc0d0 --- /dev/null +++ b/Basic Algorithm Scripting/repeat-a-string-repeat-a-string.json @@ -0,0 +1 @@ +{"index.js":"function repeatStringNumTimes(str, num) {\n // repeat after me\n let repeatedString = [];\n str = str.split('');\n if(num <= 0){\n return \"\";\n }\n for(let i=0; i{\n let largest = a[0];\n // loop through each array looking for the largest\n for(let i =0;i< a.length;i++){\n if(a[i] >= largest){\n largest = a[i];\n }\n } \n // find the largest and puts into the array of the largest ones\n largestArray.push(largest);\n });\n return largestArray;\n}\n\nlargestOfFour([[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/Basic Algorithm Scripting/slice-and-splice.json b/Basic Algorithm Scripting/slice-and-splice.json new file mode 100644 index 0000000..dc61438 --- /dev/null +++ b/Basic Algorithm Scripting/slice-and-splice.json @@ -0,0 +1 @@ +{"index.js":"function frankenSplice(arr1, arr2, n) {\n // It's alive. It's alive!\n let newArray = arr2.slice(0);\n newArray.splice(n,0,...arr1);\n return newArray;\n}\n\nfrankenSplice([1, 2, 3], [4, 5], 1);"} \ No newline at end of file diff --git a/Basic Algorithm Scripting/title-case-a-sentence.json b/Basic Algorithm Scripting/title-case-a-sentence.json new file mode 100644 index 0000000..2bbf77f --- /dev/null +++ b/Basic Algorithm Scripting/title-case-a-sentence.json @@ -0,0 +1 @@ +{"index.js":"function titleCase(str) {\n let word;\n let newString = [];\n // make the string into an array\n str = str.split(' ');\n // loop though each word\n for(let i =0; i < str.length; i++){\n // split the word to make it an array\n word = str[i].split('');\n // change the first letter to its uppercase one\n word[0] = word[0].toUpperCase();\n // make the rest of the word lower case \n for(let j =1; j < word.length;j++){\n word[j] = word[j].toLowerCase();\n }\n // join the word to make it a string\n word = word.join('');\n newString.push(word);\n }\n newString = newString.join(' ');\n return newString;\n}\n\ntitleCase(\"I'm a little tea pot\");"} \ No newline at end of file diff --git a/Basic Algorithm Scripting/truncate-a-string.json b/Basic Algorithm Scripting/truncate-a-string.json new file mode 100644 index 0000000..991f46a --- /dev/null +++ b/Basic Algorithm Scripting/truncate-a-string.json @@ -0,0 +1 @@ +{"index.js":"function truncateString(str, num) {\n // Clear out that junk in your trunk\n if(num < str.length){\n let newString = [];\n str = str.split('');\n for(let i =0;i < num; i++){\n newString[i] = str[i];\n }\n newString.push(\"...\");\n newString = newString.join('');\n return newString;\n }\n return str;\n}\n\ntruncateString(\"A-tisket a-tasket A green and yellow basket\", 8);"} \ No newline at end of file diff --git a/Basic Algorithm Scripting/where-do-i-belong.json b/Basic Algorithm Scripting/where-do-i-belong.json new file mode 100644 index 0000000..62087fe --- /dev/null +++ b/Basic Algorithm Scripting/where-do-i-belong.json @@ -0,0 +1 @@ +{"index.js":"function getIndexToIns(arr, num) {\n // Find my place in this sorted array.\n let i =0;\n // sort the array \n arr.sort((a,b) => a - b);\n // loop through the array and breaks out when find the first greater value\n for(i =0; i < arr.length; i++){\n if(arr[i] >= num){\n break;\n }\n }\n// we return the index because\n//it should be right before the first great value\n return i;\n}\n\nconsole.log(getIndexToIns([5, 3, 20, 3], 2));"} \ No newline at end of file diff --git a/Intermediate Algorithm Scripting/diff-two-arrays.json b/Intermediate Algorithm Scripting/diff-two-arrays.json new file mode 100644 index 0000000..a8d29b1 --- /dev/null +++ b/Intermediate Algorithm Scripting/diff-two-arrays.json @@ -0,0 +1 @@ +{"index.js":"function diffArray(arr1, arr2) {\n var newArr = [];\n // Same, same; but different.\n // merge the two arrays\n let mergedArrays = arr1.concat(arr2);\n // verify different element for each array\n for(let i = 0; i < mergedArrays.length; i++){\n if(arr1.indexOf(mergedArrays[i]) === -1){\n newArr.push(mergedArrays[i]);\n }\n if(arr2.indexOf(mergedArrays[i]) === -1){\n newArr.push(mergedArrays[i]);\n }\n }\n \n \n return newArr;\n}\n\ndiffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);"} \ No newline at end of file diff --git a/Intermediate Algorithm Scripting/seek-and-destroy.json b/Intermediate Algorithm Scripting/seek-and-destroy.json new file mode 100644 index 0000000..4c09b02 --- /dev/null +++ b/Intermediate Algorithm Scripting/seek-and-destroy.json @@ -0,0 +1 @@ +{"index.js":"function destroyer(arr) {\n // Remove all the values\n for(let i = 0; i < arguments[0].length;i++){\n for(let j =1;j < arguments.length;j++){\n if(arguments[0][i] === arguments[j]){\n arr.splice(i,1);\n i--; // to adjust the i since it's being spliced\n }\n }\n }\n \n return arr;\n}\n\nconsole.log(destroyer([2, 3, 2, 3], 2, 3));"} \ No newline at end of file diff --git a/Intermediate Algorithm Scripting/sum-all-numbers-in-a-range.json b/Intermediate Algorithm Scripting/sum-all-numbers-in-a-range.json new file mode 100644 index 0000000..d1fb163 --- /dev/null +++ b/Intermediate Algorithm Scripting/sum-all-numbers-in-a-range.json @@ -0,0 +1 @@ +{"index.js":"function sumAll(arr) {\n let total = 0;\n // sort the array \n arr = arr.sort((a,b)=> a-b);\n //sum the range of number between the lowest to the highest\n for( let i = arr[0];i <= arr[arr.length -1];i++){\n total+= i;\n }\n return total;\n}\n\nconsole.log(sumAll([1, 4]));"} \ No newline at end of file