forked from JClutch/Test-Bank
-
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
Jason McCutchan
authored and
Jason McCutchan
committed
Mar 21, 2018
1 parent
d2daa50
commit 7f9c007
Showing
4 changed files
with
81 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,30 @@ | ||
## Prompt | ||
|
||
Given the following code snippet below, please finish the cleanseFunction so that it doesn't break the for loop and so that in the for loop it console logs either the random number or the error message. | ||
|
||
``` | ||
function randomChanceError(x){ | ||
var i; | ||
if(typeof x !== "number"){ | ||
i = Math.round(Math.random() * 100) | ||
} else{ | ||
i = x | ||
} | ||
if(i % 2 === 0){ | ||
return i; | ||
} else{ | ||
throw new Error('Randomly throw error!') | ||
} | ||
} | ||
function cleanseFunction(fn){ | ||
/*YOUR CODE HERE*/ | ||
} | ||
var cleanFunction = cleanseFunction(randomChanceError) | ||
for (var i=0; i < 10; i++) { | ||
console.log(cleanFunction()) | ||
} | ||
``` |
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,30 @@ | ||
function randomChanceError(x){ | ||
var i; | ||
if(typeof x !== "number"){ | ||
i = Math.round(Math.random() * 100) | ||
} else{ | ||
i = x | ||
} | ||
if(i % 2 === 0){ | ||
return i; | ||
} else{ | ||
throw new Error('Randomly throw error!') | ||
} | ||
} | ||
|
||
function cleanseFunction(fn){ | ||
return () => { | ||
try{ | ||
return fn() | ||
} catch(err){ | ||
return err.message | ||
} | ||
} | ||
} | ||
|
||
var cleanFunction = cleanseFunction(randomChanceError) | ||
|
||
|
||
for (var i=0; i < 10; i++) { | ||
console.log(cleanFunction()) | ||
} |
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,21 @@ | ||
# Merge Linked-Lists solution | ||
|
||
This problem has varying levels of difficulties: | ||
|
||
Easy: Return an Array of the summed values | ||
Medium: Return a Linked List with the node values being the summed values | ||
Hard: Return a Linked List with the node values being the summed values in linear time | ||
|
||
Keys things the person will hopefully ask about are - | ||
|
||
1.) Clarificaiton of the inputs | ||
2.) What does the LL look like and show their familiarity with the data structure but also to make sure there is a common understanding what the data structure will look like between the interviewer and interviewee | ||
3.) **MOST IMPORTANTLY** Can they expect linked lists with differing amounts of nodes (Yes they can!) | ||
|
||
General outline to the solution is - | ||
|
||
* Defining a linked list constructor and creating an instance of it | ||
* Recursively iterating through both linked lists at the same time with two pointers (one for each list) | ||
* Checking inside the recursion if the pointer has reached null | ||
* Adding the node.values that the pointers are pointing to and passing that into the addToTail method of your returning link list | ||
* Recurse until both pointers reach null and the return the newly created linked list |
File renamed without changes.