Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# EricWashburn
19 changes: 12 additions & 7 deletions problems/problem1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@ var assert = require('assert');

// we need 5 test cases. I provided 1 input
let inputs = [
""
"", "john", "1a2s3d", "23", "Telephone"
]

let outputs = [

undefined, "j", "1", "2", "T"
]

// Make this function return the first letter of the string that is passed to it. If the string does not have a first letter, return undefined

// Make this function return the first character of the string that is passed to it. If the string does not have a first letter, return undefined
function f(str) {

if(str.length === 0) {
return undefined;
}
return str[0];
}

function runTest(i) {
var expected = outputs[i];
var actual = f(inputs[i]);
assert.deepEqual(actual, expected);
var expected = outputs[i];
var actual = f(inputs[i]);
assert.deepEqual(actual, expected);
}

runTest(0);
runTest(1);
runTest(2);
runTest(3);
runTest(4);

10 changes: 7 additions & 3 deletions problems/problem2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ var assert = require('assert');

// we need 5 test cases.
let inputs = [

"", "john", "1a2s3d", "23", "Telephone"
]

let outputs = [

undefined, "n", "d", "3", "e"
]

// Make this function return the last letter of the string that is passed to it. If the string does not have a last letter, return undefined
function f(str) {

if (str.length === 0) {
return undefined;
} else {
return (str[str.length-1]);
}
}

function runTest(i) {
Expand Down
31 changes: 24 additions & 7 deletions problems/problem3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,42 @@ var assert = require('assert');
// we need 7 test cases. I've provided 2.
let inputs = [
[2, 4],
[-3, 3]
[-3, 3],
[1, 2],
[0, 0],
["a",8],
[0,"r"],
[1, 2]
]

let outputs = [
6,
0
0,
3,
0,
undefined,
undefined,
3
]

/*
Make this function return the sum of the two numbers that are passed to it. If one of the numbers is not passed, or if anything other than numbers are passed, return undefined.
*/
function f(x, y) {

function f(x) {
var results = x[0] + x[1];

if (isNaN(results)) {
return undefined;
} else {
return results;
}
}


function runTest(i) {
var expected = outputs[i];
var actual = f(inputs[i]);
assert.deepEqual(actual, expected);
var expected = outputs[i];
var actual = f(inputs[i]);
assert.deepEqual(actual, expected);
}

runTest(0);
Expand Down
21 changes: 17 additions & 4 deletions problems/problem4.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@ var assert = require('assert');
// we need 8 test cases. I've provided the first 2
let inputs = [
["hello", 4],
["", 2]
["", 2],
["john", 3],
["john", 3],
["john", 3],
["john", 3],
["john", 3],
["bohn", 3]
]

let outputs = [
"o",
undefined
undefined,
"n",
"n",
"n",
"n",
"n",
"n"

]

/*
Expand All @@ -20,8 +33,8 @@ f(["", 4]); // undefined
f(["abc", 0]); // a

*/
function f(arr) {
function f(str, index) {
return str[index];
}

function runTest(i) {
Expand Down
24 changes: 20 additions & 4 deletions problems/problem5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,34 @@ var assert = require('assert');

// we need 5 test cases.
let inputs = [
[2, 7]
[2, 7],
[1, 2],
[2, 3],
[3, 4],
[4, 5]
]

let outputs = [
14
14,
2,
6,
12,
20
]

/*
Make this function return the product of the two numbers that are passed to it. If one of the numbers is not passed, or if anything other than numbers are passed, return undefined.
*/
function f(x, y) {

function f(arr) {
var x = arr[0];
var y = arr[1];
var result = x*y;
if (isNaN(result)) {
return undefined;
} else {
return result;
}

}

function runTest(i) {
Expand Down
34 changes: 30 additions & 4 deletions problems/problem6.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ var assert = require('assert');
// we need 6 test cases.
let inputs = [
["add", 10, 20],
["chair", 20, 10]
["chair", 20, 10],
["mult", 20, 10],
["sub", 20, 10],
["add", 20, 10],
["add", 30, 5]
]

let outputs = [
30
30,
undefined,
200,
10,
30,
35
]

/*
Expand All @@ -21,8 +30,25 @@ f(["mult", 2, 3]); // 6
f(["spoof", 10, 10]); // undefined

*/
function f(arr) {


function f(operation) {
var operation1 = operation[0];
var firstArgument1 = operation[1];
var secondArgument2 = operation[2];
var add = firstArgument1 + secondArgument2;
var sub = firstArgument1 - secondArgument2;
var mult = firstArgument1 * secondArgument2;
if (operation[0] === "add") {
return add;
} else if ( operation1 === "sub") {
return sub;
} else if ( operation1 === "mult") {
return mult;
} else {
return undefined;
}


}

function runTest(i) {
Expand Down
32 changes: 29 additions & 3 deletions problems/problem7.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ var assert = require('assert');

// we need 7 test cases.
let inputs = [

["foo", 3],
["foo", 4],
["foo", 5],
["foo", 6],
["foo", 7],
["foo", "er"],
["foo", -1]
]

let outputs = [

"foofoofoo",
"foofoofoofoo",
"foofoofoofoofoo",
"foofoofoofoofoofoo",
"foofoofoofoofoofoofoo",
undefined,
"",
]

/*
Expand All @@ -19,7 +31,21 @@ f(["foo", 3]) // "foofoofoo"
f(["fo", 3]) // "fofofo"
f(["foo", -1]) // undefined
*/
function f(arr) {

function f(str) {
var word = str[0];
var mult = str[1];
var emptyString = "";
if (typeof word !== 'string') {
return undefined;
} else if (isNaN(mult)) {
return undefined;
} else if (mult >= 0) {
return word.repeat(mult);
} else {
return emptyString;
}


}

Expand Down
19 changes: 16 additions & 3 deletions problems/problem8.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@ var assert = require('assert');

// we need 5 test cases.
let inputs = [
"hello",
"what are",
"find",
"the",
"last"

]

let outputs = [

"olleh",
"era tahw",
"dnif",
"eht",
"tsal"
]

/*
Make this function return the input string, reversed. For example "hello" would return "olleh" and "how are you" would return "uoy era woh".
You must use a for loop for this exercise.
*/
function f(str) {

function f(x) {
var reversed = ""
for (var i = x.length-1; i >= 0; i--) {
reversed += x[i];
}
return reversed;
}

function runTest(i) {
Expand Down
26 changes: 24 additions & 2 deletions problems/problem9.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,41 @@ var assert = require('assert');

// we need 5 test cases.
let inputs = [

"one seven",
"two five",
"three two",
"",
"nineteen"
]

let outputs = [

"one",
"two",
"three",
"",
"nineteen"

]

/*
Make this function return the longest word in the input string. If the input string is empty then return an empty string.
If multiple words have the same length, return the last one that matches.
*/
function f(str) {
var longestWord = '';
var longest = 0;
//slit sentence up into an array
var splitString = str.split(" ");
console.log(splitString);
for (var i = 0; i < splitString.length; i++) {
if (longest > splitString[i].length) {
longest = splitString[i].length;
longestWord = splitString[i];
return longestWord;
}
}

//find length of each item
}

function runTest(i) {
Expand Down