-
Notifications
You must be signed in to change notification settings - Fork 2
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
4 changed files
with
78 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,34 @@ | ||
|
||
var getMax = function(param: Array<string>): number { | ||
var length = 0; | ||
var initialValue = 0; | ||
for (var i = 0; i < param.length; i++) { | ||
length = param[i].length; | ||
if (length > initialValue) { | ||
initialValue = length; | ||
} | ||
} | ||
return initialValue; | ||
} | ||
//(max length + 2) - (length of array element) = number of spaces before 2nd asterisk | ||
var createPicture = function(array: Array<string>): void { | ||
var maxLength = getMax(array); | ||
var result = ""; | ||
for (var i = 0; i < maxLength + 2; i++) { | ||
result += "*"; | ||
} | ||
console.log(result); | ||
for (var i = 0; i < array.length; i++) { | ||
var numberSpaces = maxLength - array[i].length; | ||
var spaces = '' | ||
for (var j = 0; j < numberSpaces; j++) { | ||
spaces += ' '; | ||
} | ||
console.log('*' + array[i] + spaces + '*'); // print elements of array in their own lines, adds asterisks | ||
} | ||
console.log(result); | ||
}; | ||
createPicture(["Hello", "World", "in", "a", "frame"]); | ||
createPicture(["Bienvenidos", "A", "La", "Mundo", "del", "Tyler"]); | ||
createPicture(["I", "see", "what", "you", "are", "saying."]) | ||
createPicture(["I", "ran", "totally", "bananahammocks", "on", "your", "ass."]) |
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,15 @@ | ||
var isPalindrome = function(param: string): boolean { | ||
var stringLength = param.length; | ||
|
||
for (var i = 0; i < stringLength; i++) { | ||
if (param[i] === param[stringLength - 1]) { | ||
stringLength--; | ||
} | ||
else { | ||
return false | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
console.log(isPalindrome('mrowlatemymetalworm')); |
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,19 @@ | ||
_.last = function(array, n) { | ||
var result = []; | ||
if (n === undefined) { | ||
return array[array.length - 1]; | ||
} | ||
var m; | ||
if (array.length < n) { | ||
m = array.length; | ||
} else { | ||
m = n; | ||
} | ||
var last = array.slice(-m); | ||
result.push(last); | ||
|
||
return result; | ||
}; | ||
var sampleArray = [0, 1, 2, 3, 4, 5] | ||
var lastThree = _.last(sampleArray, 3); | ||
console.log(lastThree); |
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,10 @@ | ||
//Given an array of integers, return indices of the two numbers such that they add up to a specific target. | ||
|
||
//You may assume that each input would have exactly one solution, and you may not use the same element twice. | ||
|
||
|
||
//EXAMPLE | ||
//Given nums = [2, 7, 11, 15], target = 9, | ||
|
||
//Because nums[0] + nums[1] = 2 + 7 = 9, | ||
//return [0, 1]. |