-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
14 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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);"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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\"));"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]));"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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);"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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\"]);"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<num; i++){\n repeatedString.push(...str);\n }\n repeatedString = repeatedString.join('');\n return repeatedString;\n}\n\nrepeatStringNumTimes(\"abc\", 3);"} |
1 change: 1 addition & 0 deletions
1
Basic Algorithm Scripting/return-largest-numbers-in-arrays.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"index.js":"function largestOfFour(arr) {\n // You can do this!\n let largestArray = [];\n\n arr.forEach((a) =>{\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]]);"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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);"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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\");"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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);"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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));"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]);"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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));"} |
1 change: 1 addition & 0 deletions
1
Intermediate Algorithm Scripting/sum-all-numbers-in-a-range.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]));"} |