Skip to content

Commit

Permalink
add misc files
Browse files Browse the repository at this point in the history
  • Loading branch information
hajkowicz committed Sep 8, 2018
1 parent e7d9cfe commit cdda50d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
34 changes: 34 additions & 0 deletions frame.ts
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."])
15 changes: 15 additions & 0 deletions palindrome.ts
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'));
19 changes: 19 additions & 0 deletions random.ts
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);
10 changes: 10 additions & 0 deletions twosum.ts
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].

0 comments on commit cdda50d

Please sign in to comment.