From 0d6d8ef6a828912934555f4373e017cd28c60f09 Mon Sep 17 00:00:00 2001 From: Nathan Schmidt Date: Mon, 15 Jan 2018 10:09:17 -0500 Subject: [PATCH] some message --- .DS_Store | Bin 0 -> 8196 bytes package-lock.json | 326 +++++++++++++++++++++++++++++++++ paperproblems/.DS_Store | Bin 0 -> 12292 bytes paperproblems/HOF/problem1.txt | 5 +- src/HOF/problem1.js | 112 ++++++++++- src/__proto__/problem1.js | 2 +- src/exceptions/problem1.js | 35 +++- src/exceptions/problem1a.js | 46 +++++ src/return/problem1.js | 13 +- src/return/problem1a.js | 17 ++ 10 files changed, 534 insertions(+), 22 deletions(-) create mode 100644 .DS_Store create mode 100644 package-lock.json create mode 100644 paperproblems/.DS_Store create mode 100644 src/exceptions/problem1a.js create mode 100644 src/return/problem1a.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..65228cd96226bfb7a369acb3aa1f922014fb1043 GIT binary patch literal 8196 zcmeHMO>7%Q6n@W1+ue23O#X_~mef^HlqhL%QbN-}sq@!T+R_Loanc0L+PfqRn_c5w z+YM2q01}ld1O;(GLR^~AB7`^~Ar5c=A)peyfGR;j&Y&040Z8%? zz)Mu8IKcCX`ZDgz1tC3G8dF3M=)0mHVxVv*dz5!48TaLakis2MxC8n#qaUH5H#_-7 zz3zZp;vI?RBRE;`w?X{V{zpXsb=IBqO<9Yba1TefbK zWF^cWR;4_en6`@vS9SAFpPHNST85^l{rZsVPM7M#wrwug)%2*L7gMaZ-?m)Uu=Lyt z*U6+|X?C&C&Rd!@nGoY84b7cSvAUt0ULe;Y)zU`|$4DEd;m%4je^M+mH`me8-4?yK zbG|J)*Aa_Rz3b3D^YiSSB<*hL>OD1{oj-qZap|o~m*4*EbAbx_Zx*OogVGn9Lu5LI zApudyErR?U}tI_ny?<&5e%hh&OXI)vNtjBWWJC&j8Vs+q}~s;l>! zX2N(zcaj;~%+FZPn5&<4x#o;x=iGizIcAVA*QFTCJNhF!IT{6hfZ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ibCgYI?)vw3^8{4C!nW1cmSnS0FqnlkeVmZG;&cpJrkyittX67sf-(buF` z@hsq3z_Wm70nY-S1+KsXQ%GlmfI|)iyL97Fuu7s}E9wLOl}(Lf9IU>fX<`oc3FBCl zCgosfXmA4CwVHpeq3 zZ=gu?n9omIe5J0rH{pHwh(hmQz}J7_nhRhpt|r%96S?NrIl=ZVWIxqe6unj(5hKP(1ay t-=R5uA)3zgM!0m;sLj=`*+&38p62cUKwo=~OHOFc+y4s*(B0ts|DP_r@*4mE literal 0 HcmV?d00001 diff --git a/paperproblems/HOF/problem1.txt b/paperproblems/HOF/problem1.txt index 5985535..523714e 100644 --- a/paperproblems/HOF/problem1.txt +++ b/paperproblems/HOF/problem1.txt @@ -3,10 +3,11 @@ You don't know what it does, but there are clues at the bottom of this file Use these clues to describe what filter is. Specifically: - How many parameters does it have +two - What are the types of the parameters +array, function - What does it do? - - +it takes an array and applies a function which assesses whether or not an element of an array is divisible by itself, depending on if the function returns a boolean of true the element is either passed to a new array using.push or ignored from this new array. var evenNumbers = [2, 4, 6, 8, 10]; var oddNumbers = [3, 5, 7, 9]; diff --git a/src/HOF/problem1.js b/src/HOF/problem1.js index 0ed585e..f63a2a7 100644 --- a/src/HOF/problem1.js +++ b/src/HOF/problem1.js @@ -1,5 +1,15 @@ -function callNoException(f, arg) { + function callNoException(f, arg) { + + try { + f(arg); + } + catch(err) { + return null; + } + return arg; + + } // if f(arg) throws an exception, return null // otherwise return what f(arg) returned // Example: @@ -9,9 +19,28 @@ function callNoException(f, arg) { // } // callNoException(throwsZero, 0) returns null // callNoException(throwsZero, 12) returns 12 -} -function callNoNull(f, arg) { + + function callNoNull(f, arg) { + + + + try { f(arg) + if (f(arg) === null) { + throw "it's null"; + } + + + return arg + + } + catch(err){ throw new Error ("null alert!"); + + } +} + + + // if f(arg) returns null, throw an exception // otherwise return what f(arg) returned // Example: @@ -22,10 +51,40 @@ function callNoNull(f, arg) { // callNoNull(nullZero, 0) throws an exception // callNoNull(nullZero, 12) returns 12 + var exceptionalize = function(f) { + return function g(arg) { + arg = f + + if (arg !== null ); + return arg; + + + try { + + g(f); + + if (arg === null){ + + + throw new Error ("error!"); + } + + + + } -} -function exceptionalize(f) { + catch(err){ throw new Error ("bazinga!"); + + } + return arg + } + + return arg + + + } + // returns a new function // this function takes 1 input, called arg // if f(arg) is null, this new function throws an exception @@ -40,9 +99,40 @@ function exceptionalize(f) { // g(0) throws an exception // g(12) returns 12 -} -function nullify(f) { + + var nullify = function(f) { + return function newFunction(arg) { + var numNum = "" + try { + newFunction(arg); + if (arg == 0) throw new Error ("whoops"); + + numNum = arg; + return numNum + } + + catch(err) { + return null + } + return numNum; + + } + return function g(arg) { + try { + g(numNum) + + + return arg + } + catch (err) { + return null; + done() + } + } + + } + // returns a new function // this function takes 1 input, called arg // if f(arg) throws an exception, this new function returns null @@ -56,9 +146,13 @@ function nullify(f) { // g(0) returns null // g(12) throws an exception -} + function map(lst, f) { + lst = [a, b]; + f = {} +lst.map(function(lst){ return f.toUppercase()} + // lst is an array and f is a function // map returns an array with the same number of elements as lst // if lst = [a1, a2, a3, a4, a5] then map(lst, f) returns [f(a1), f(a2), f(a3), f(a4), f(a5)] @@ -69,7 +163,7 @@ function map(lst, f) { // // function toUpperCase(str) { return str.toUpperCase(); } // map(["bob", "susie"], toUpperCase) returns ["BOB", "SUSIE"] -} + function filter(lst, f) { // lst is an array and f is a function diff --git a/src/__proto__/problem1.js b/src/__proto__/problem1.js index 820a78d..21857b0 100644 --- a/src/__proto__/problem1.js +++ b/src/__proto__/problem1.js @@ -2,5 +2,5 @@ var parent = {x: 5, y: 6, z: 8}; var child = {x : 10}; - +child.__proto__ = parent; module.exports = {parent, child} \ No newline at end of file diff --git a/src/exceptions/problem1.js b/src/exceptions/problem1.js index f54c8f8..96f321f 100644 --- a/src/exceptions/problem1.js +++ b/src/exceptions/problem1.js @@ -1,22 +1,51 @@ + + function first(arr) { // Throw an exception if the array has no elements // Otherwise return the first element + if (arr[0] === undefined) { + throw "error"; + } else { return arr[0]; + + } + } - +// console.log(first(arr1)); function detective(i) { function suspect(i) { - if(i * 7 % 3 == 0) throw new Error("Bad i!"); + if(i * 7 % 3 === 0) {throw new Error("Bad i!")}; + } + + try { + suspect(i); } + catch(err) { + return "something fishy"; + } + + return "everything ok" +} + + // detective checks to see if the suspect throws an exception on input i. // Returns "everything ok" if the suspect doesn't. // Returns "something fishy" if the suspect does. -} + function assignFlight(name) { var flightNumber = ((name.length * 7) % 20) + "0"; var terrorSuspects = ["bob", "eric", "susie"]; // if the name is a terror suspect, throw an exception // Otherwise, return the flight number + if (name == "bob" || name == "eric" || name == "susie") {throw new Error ("terrorist!"); + } + try { + assignFlight(name); + } + catch(err) { + return "terrorist!"; + } + return flightNumber } module.exports = {first, detective, assignFlight} \ No newline at end of file diff --git a/src/exceptions/problem1a.js b/src/exceptions/problem1a.js new file mode 100644 index 0000000..044d7cf --- /dev/null +++ b/src/exceptions/problem1a.js @@ -0,0 +1,46 @@ + + +function first(arr) { + // Throw an exception if the array has no elements + // Otherwise return the first element + if (arr[0] === undefined) { + throw "error"; + } else { return arr[0]; + + } + +} +// console.log(first(arr1)); +function detective(i) { + function suspect(i) { + if(i * 7 % 3 == 0) {throw new Error("Bad i!"); + + } else { throw new Error("everything ok") +} +} + try { + suspect(i); + } + catch(err) { + return console.log("something fishy"); + } +} + + + + + + + // detective checks to see if the suspect throws an exception on input i. + // Returns "everything ok" if the suspect doesn't. + // Returns "something fishy" if the suspect does. + + +function assignFlight(name) { + var flightNumber = ((name.length * 7) % 20) + "0"; + var terrorSuspects = ["bob", "eric", "susie"]; + // if the name is a terror suspect, throw an exception + // Otherwise, return the flight number +} + +module.exports = {first, detective, assignFlight} \ No newline at end of file diff --git a/src/return/problem1.js b/src/return/problem1.js index c8f7b32..b6df18c 100644 --- a/src/return/problem1.js +++ b/src/return/problem1.js @@ -1,17 +1,16 @@ -// Remove as many characters from this function without changing its meaning. -// In other words, make this function as succinct as possible -// Also, remove these comments + function f(x) { if(x > 10) { return "hello"; } else if(x > 5) { return "goodbye"; - } else { - return undefined; - } + } + } -module.exports = f; // Don't delete this line but remove this comment. + + +module.exports = f; diff --git a/src/return/problem1a.js b/src/return/problem1a.js new file mode 100644 index 0000000..27c3d74 --- /dev/null +++ b/src/return/problem1a.js @@ -0,0 +1,17 @@ + + +function f(x) { + if(x > 10) { + return "hello"; + } else if(x > 5) { + return "goodbye"; + } else { + return undefined; + } +} + + + +module.exports = f; + +