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
// Using the JavaScript language, have the function StringScramble(str1,str2) take both parameters being passed and return the string true if a portion of str1 characters can be rearranged to match str2, otherwise return the string false. For example: if str1 is "rkqodlw" and str2 is "world" the output should return true. Punctuation and symbols will not be entered with the parameters. | |
// Input = "cdore" & str2= "coder" Output = "true" | |
// Input = "h3llko" & str2 = "hello" Output = "false" | |
function StringScramble( str1, str2 ) { | |
var output = ''; | |
for ( var i = 0; i < str2.length; i++ ) { | |
var pattern = new RegExp( str2[i] ); | |
if ( str1.match( pattern ) && str1.match( pattern )[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
// Using the JavaScript language, have the function ArithGeoII(arr) take the array of numbers stored in arr and return the string "Arithmetic" if the sequence follows an arithmetic pattern or return "Geometric" if it follows a geometric pattern. If the sequence doesn't follow either pattern return -1. An arithmetic sequence is one where the difference between each of the numbers is consistent, where as in a geometric sequence, each term after the first is multiplied by some constant or common ratio. Arithmetic example: [2, 4, 6, 8] and Geometric example: [2, 6, 18, 54]. Negative numbers may be entered as parameters, 0 will not be entered, and no array will contain all the same elements. | |
// Input = 5,10,15 Output = "Arithmetic" | |
// Input = 2,6,18,54 Output = "Geometric" | |
// Input = 2,4,16,24 Output = -1 | |
// Input = 2,4,6,14 Output = -1 | |
function ArithGeoII( arr ) { | |
var math; | |
var number = [ (arr[1] - arr[0]), (arr[1] / arr[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
// Using the JavaScript language, have the function ArrayAddition(arr) take the array of numbers stored in arr | |
// and return the string true if any combination of numbers in the array can be added up to equal the largest | |
// number in the array, otherwise return the string false. For example: if arr contains [4, 6, 23, 10, 1, 3] the | |
// output should return true because 4 + 6 + 10 + 3 = 23. The array will not be empty, will not contain all the | |
// same elements, and may contain negative numbers. | |
// Input = 5,7,16,1,2 Output = "false" | |
// Input = 3,5,-1,8,12 Output = "true" | |
function ArrayAddition( arr ) { |
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
// Using the JavaScript language, have the function RunLength(str) take the str parameter being passed and return a compressed // version of the string using the Run-length encoding algorithm. This algorithm works by taking the occurrence of each | |
// repeating character and outputting that number along with a single character of the repeating sequence. | |
// For example: "wwwggopp" would return 3w2g1o2p. The string will not contain any numbers, punctuation, or symbols. | |
// Input = "aabbcde" Output = "2a2b1c1d1e" | |
// Input = "wwwbbbw" Output = "3w3b1w" | |
function RunLength( str ) { | |
var output = ''; | |
while ( str.length > 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
// Using the JavaScript language, have the function PrimeTime(num) take the num parameter being passed and return the string | |
// true if the parameter is a prime number, otherwise return the string false. The range will be between 1 and 2^16. | |
// Input = 19 Output = true | |
// Input = 110 Output = false | |
function PrimeTime( num ) { | |
for ( var i = 2; i < num; i++ ) { | |
if ( num % i == 0 ) | |
return false; |
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
// Using the JavaScript language, have the function ThirdGreatest(strArr) take the array of strings stored in strArr and return // the third largest word within in. So for example: if strArr is ["hello", "world", "before", "all"] your output should be | |
// world because "before" is 6 letters long, and "hello" and "world" are both 5, but the output should be world because it | |
// appeared as the last 5 letter word in the array. If strArr was ["hello", "world", "after", "all"] the output should be after // because the first three words are all 5 letters long, so return the last one. The array will have at least three strings and // each string will only contain letters. | |
// Input = "coder","byte","code" Output = "code" | |
// Input = "abc","defg","z","hijk" Output = "abc" |
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
// Using the JavaScript language, have the function NumberSearch(str) take the str parameter, search for all the numbers in the | |
// string, add them together, then return that final number. For example: if str is "88Hello 3World!" the output should be 91. | |
// You will have to differentiate between single digit numbers and multiple digit numbers like in the example above. So | |
// "55Hello" and "5Hello 5" should return two different answers. Each string will contain at least one letter or symbol. | |
// Input = "75Number9" Output = 84 | |
// Input = "10 2One Number*1*" Output = 13 | |
function numCoverter( str ) { | |
var sum = 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
// Using the JavaScript language, have the function SwapCase(str) take the str parameter and swap the case of each character. | |
// For example: if str is "Hello World" the output should be hELLO wORLD. Let numbers and symbols stay the way they are. | |
// Input = "Hello-LOL" Output = "hELLO-lol" | |
// Input = "Sup DUDE!!?" Output = "sUP dude!!?" | |
function SwapCase( str ) { | |
var swap = ''; | |
for ( var i = 0; i < str.length; i++ ) { | |
if ( str[i] == str[i].toUpperCase() ) |
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
// Using the JavaScript language, have the function DashInsert(num) insert dashes ('-') between each two odd numbers in num. | |
// For example: if num is 454793 the output should be 4547-9-3. Don't count zero as an odd number. | |
// Input = 99946 Output = "9-9-946" | |
// Input = 56730 Output = "567-30" | |
function DashInsert( num ) { | |
var dashI = ''; | |
var nums = ( num ).toString().split( '' ); | |
for ( var i = 0; i < nums.length; i++ ) { |
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
// Using the JavaScript language, have the function MeanMode(arr) take the array of numbers stored in arr and return 1 if | |
// the mode equals the mean, 0 if they don't equal each other (ie. [5, 3, 3, 3, 1] should return 1 because the mode (3) equals | |
// the mean (3)). The array will not be empty, will only contain positive integers, and will not contain more than one mode. | |
// Input = 1, 2, 3Output = 0 | |
// Input = 4, 4, 4, 6, 2Output = 1 | |
function MeanMode( arr ) { | |
var sum = 0; | |
arr.forEach( function ( el, idx, ary ) { |