Skip to content

Commit

Permalink
added clean functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason McCutchan authored and Jason McCutchan committed Mar 21, 2018
1 parent d2daa50 commit 7f9c007
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Coding_Challenges/CleanFunctions/README.md
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())
}
```
30 changes: 30 additions & 0 deletions Coding_Challenges/CleanFunctions/SOLUTION.js
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())
}
21 changes: 21 additions & 0 deletions Whiteboarding/Merge_LinkList/SOLUTION.md
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.

0 comments on commit 7f9c007

Please sign in to comment.