├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── Solutions ├── A8_JS_fun_solutions.js ├── Alberto03_solutions.js ├── Amarjit_JS_fun.js ├── BadrEladr.js ├── BobTheCool55_Solution.js ├── Clifftech123_solution.js ├── Corleone0007_Solutions.js ├── Indrajith_solution.js ├── JMCrawf_Solution.js ├── Krios_Solutions.js ├── Maurice972_solutions.js ├── Mohamed_Cheour_Solutions.js ├── My-Solutions-ML.js ├── MySolutions_ON.js ├── OddOrEven.js ├── OkelloSam21_solutions.json ├── Osvaldo_Solutions.js ├── RNtaate_JS_fun_solutions.js ├── RavisSolution.js ├── aal_solution.js ├── adrianSolution.js ├── alex_solutions.js ├── arham2002.js ├── asha_JS_solution.js ├── ayushi_solutions.js ├── brianwhelandublin.js ├── chirag_solutions.js ├── chouettevan_solution.js ├── cyborg7459.js ├── d3kelleyy.js ├── danmachlenkin.js ├── danteSadeghiSolutions.js ├── david_001_solutions copy.js ├── david_001_solutions.js ├── dimitrisz123.js ├── eimantas20.js ├── ezClops_Solution.js ├── filterRecurse_solution.js ├── fokouarnaud_solution.js ├── fun-soulution.js ├── fun.js ├── funExercises.js ├── fun_Js_Bhavesh.js ├── fun_solution.js ├── fun_solution_mla.js ├── fun_solutions_hazamaswag.js ├── giuffrida_solutions.js ├── goosNJuice_Solution.js ├── gt_solutions.js ├── hari_krishna_js_fun.js ├── hegeman_thomas_solutions.js ├── hirasolutions.js ├── ielisman.js ├── ishangupta_solution.js ├── js-fun-practice-vinavoovoo.js ├── justin2172021_solutions.js ├── kciccolella_solutions.js ├── khizarhashmi119.js ├── kma_solutions.js ├── kunalprakash1309.js ├── leykhan.js ├── luckynumber.js ├── luigi_solutions.js ├── mariko_971_solutions.js ├── mathewtrSolution.js ├── mayank0255_solutions.js ├── melipi_solutions.js ├── michaeljoy255.js ├── michaelzwiener.js ├── min-max.js ├── mmtbora_solutions.js ├── mulRecurse.js ├── my-solutions-GM.js ├── my-solutions-HN.js ├── my-solutions-LJ.js ├── my-solutions-j4.js ├── mySolution-mm.js ├── mySolutions-TH.js ├── mySolutions-oakj.js ├── mySolutions.js ├── mySolutionsAU.js ├── my_solution_KN.js ├── my_solution_itsnou.js ├── my_solutions.js ├── nataliaSolution.js ├── nguyen_all_solutions.js ├── presian_solution.js ├── princeo1.js ├── priya_solution.js ├── pyramid.js ├── rafia-z-solutions ├── ranran2121_solutions.js ├── raza_solutions.js ├── saeedTlb_solution.js ├── salih_solution.js ├── samkcrespo_solutions.js ├── saud06_solutions.js ├── schmeb0704_solution.js ├── solution_D.js ├── solutiongilboa48.js ├── solutions.html ├── solutionsSoldin ├── some-solutions.js ├── sudwiptokm__solutions.js ├── tari-solution.js ├── tarunmankar_sol.js ├── usergr_solution.js ├── v1zei_solutions.js └── vyasriday_solutions.js ├── index.html ├── index.js ├── package-lock.json ├── package.json ├── style.css └── test ├── Amarjit_solutions.js ├── Marulo_solution.js ├── aal_solution.js ├── chirag_solutions.js ├── david_001_solutions.js ├── justin2172021_solutions.js ├── saeedTlb_solution.js └── schmeb0704_solution.js /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/linux,windows,macos,node 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=linux,windows,macos,node 4 | 5 | ### Linux ### 6 | *~ 7 | 8 | # temporary files which can be created if a process still has a handle open of a deleted file 9 | .fuse_hidden* 10 | 11 | # KDE directory preferences 12 | .directory 13 | 14 | # Linux trash folder which might appear on any partition or disk 15 | .Trash-* 16 | 17 | # .nfs files are created when an open file is removed but is still being accessed 18 | .nfs* 19 | 20 | ### macOS ### 21 | # General 22 | .DS_Store 23 | .AppleDouble 24 | .LSOverride 25 | 26 | # Icon must end with two \r 27 | Icon 28 | 29 | # Thumbnails 30 | ._* 31 | 32 | # Files that might appear in the root of a volume 33 | .DocumentRevisions-V100 34 | .fseventsd 35 | .Spotlight-V100 36 | .TemporaryItems 37 | .Trashes 38 | .VolumeIcon.icns 39 | .com.apple.timemachine.donotpresent 40 | 41 | # Directories potentially created on remote AFP share 42 | .AppleDB 43 | .AppleDesktop 44 | Network Trash Folder 45 | Temporary Items 46 | .apdisk 47 | 48 | ### Node ### 49 | # Logs 50 | logs 51 | *.log 52 | npm-debug.log* 53 | yarn-debug.log* 54 | yarn-error.log* 55 | lerna-debug.log* 56 | 57 | # Diagnostic reports (https://nodejs.org/api/report.html) 58 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 59 | 60 | # Runtime data 61 | pids 62 | *.pid 63 | *.seed 64 | *.pid.lock 65 | 66 | # Directory for instrumented libs generated by jscoverage/JSCover 67 | lib-cov 68 | 69 | # Coverage directory used by tools like istanbul 70 | coverage 71 | *.lcov 72 | 73 | # nyc test coverage 74 | .nyc_output 75 | 76 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 77 | .grunt 78 | 79 | # Bower dependency directory (https://bower.io/) 80 | bower_components 81 | 82 | # node-waf configuration 83 | .lock-wscript 84 | 85 | # Compiled binary addons (https://nodejs.org/api/addons.html) 86 | build/Release 87 | 88 | # Dependency directories 89 | node_modules/ 90 | jspm_packages/ 91 | 92 | # TypeScript v1 declaration files 93 | typings/ 94 | 95 | # TypeScript cache 96 | *.tsbuildinfo 97 | 98 | # Optional npm cache directory 99 | .npm 100 | 101 | # Optional eslint cache 102 | .eslintcache 103 | 104 | # Microbundle cache 105 | .rpt2_cache/ 106 | .rts2_cache_cjs/ 107 | .rts2_cache_es/ 108 | .rts2_cache_umd/ 109 | 110 | # Optional REPL history 111 | .node_repl_history 112 | 113 | # Output of 'npm pack' 114 | *.tgz 115 | 116 | # Yarn Integrity file 117 | .yarn-integrity 118 | 119 | # dotenv environment variables file 120 | .env 121 | .env.test 122 | 123 | # parcel-bundler cache (https://parceljs.org/) 124 | .cache 125 | 126 | # Next.js build output 127 | .next 128 | 129 | # Nuxt.js build / generate output 130 | .nuxt 131 | dist 132 | 133 | # Gatsby files 134 | .cache/ 135 | # Comment in the public line in if your project uses Gatsby and not Next.js 136 | # https://nextjs.org/blog/next-9-1#public-directory-support 137 | # public 138 | 139 | # vuepress build output 140 | .vuepress/dist 141 | 142 | # Serverless directories 143 | .serverless/ 144 | 145 | # FuseBox cache 146 | .fusebox/ 147 | 148 | # DynamoDB Local files 149 | .dynamodb/ 150 | 151 | # TernJS port file 152 | .tern-port 153 | 154 | # Stores VSCode versions used for testing VSCode extensions 155 | .vscode-test 156 | .prettierrc 157 | ### Windows ### 158 | # Windows thumbnail cache files 159 | Thumbs.db 160 | Thumbs.db:encryptable 161 | ehthumbs.db 162 | ehthumbs_vista.db 163 | 164 | # Dump file 165 | *.stackdump 166 | 167 | # Folder config file 168 | [Dd]esktop.ini 169 | 170 | # Recycle Bin used on file shares 171 | $RECYCLE.BIN/ 172 | 173 | # Windows Installer files 174 | *.cab 175 | *.msi 176 | *.msix 177 | *.msm 178 | *.msp 179 | 180 | # Windows shortcuts 181 | *.lnk 182 | 183 | # End of https://www.toptal.com/developers/gitignore/api/linux,windows,macos,node 184 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Please note we have a **[code of conduct](https://github.com/zero-to-mastery/CodeofConduct)**, please follow it in all your interactions with the project. 4 | 5 | ## Pull Request Process 6 | 7 | 1. Please make sure to create a separate file with your solutions. **Put that file into the `Solutions` folder.** 8 | 9 | 2. After you've made your pull request, you will have to wait until a maintainer can merge your request. Please be patient, as most maintainers are volunteers. 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Zero To Mastery 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Solutions/A8_JS_fun_solutions.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | const identity = (argument) => argument; 3 | 4 | //Write a binary function addb that takes two numbers and returns their sum 5 | const addb = (a, b) => a + b; 6 | 7 | // Write a binary function subb that takes two numbers and returns their difference 8 | const subb = (a, b) => a - b; 9 | 10 | // Write a binary function mulb that takes two numbers and returns their product 11 | const mulb = (a, b) => a*b; 12 | 13 | // Write a binary function minb that takes two numbers and returns the smaller one 14 | const minb = (a, b) => a < b ? a : b; 15 | 16 | // Write a binary function maxb that takes two numbers and returns the larger one 17 | const maxb = (a, b) => a > b ? a : b; 18 | 19 | // Write a function add that is generalized for any amount of arguments 20 | const add = (...nums) => nums.reduce((a, b)=>a+b) 21 | 22 | // Write a function sub that is generalized for any amount of arguments 23 | const sub = (...nums) => nums.reduce((a, b)=>a-b) 24 | 25 | //Write a function mul that is generalized for any amount of arguments 26 | const mul = (...nums) => nums.reduce((a, b)=>a*b , 1) 27 | 28 | // Write a function min that is generalized for any amount of arguments 29 | const min = (...nums) => nums.reduce((a, b)=> Math.min(a, b)) 30 | 31 | // Write a function max that is generalized for any amount of arguments 32 | const max = (...nums) => nums.reduce((a, b)=> Math.max(a, b)) 33 | 34 | // Write a function addRecurse that is the generalized add function but uses recursion 35 | const addRecurse = (...nums) => { 36 | if (nums.length === 1) return nums[0] 37 | return nums.pop() + addRecurse(...nums); 38 | } 39 | 40 | // Write a function mulRecurse that is the generalized mul function but uses recursion 41 | const mulRecurse = (...nums) => { 42 | if (nums.length === 1) return nums[0] 43 | return nums.pop() * mulRecurse(...nums); 44 | } 45 | 46 | // Write a function minRecurse that is the generalized min function but uses recursion 47 | const minRecurse = (...nums) => { 48 | if (nums.length === 1) return nums[0] 49 | let secondNum = minRecurse(...nums.slice(1)) 50 | if (nums[0] < secondNum) return nums[0] 51 | return secondNum 52 | } 53 | 54 | // Write a function maxRecurse that is the generalized max function but uses recursion 55 | const maxRecurse = (...nums) => { 56 | if (nums.length === 1) return nums[0] 57 | let secondNum = maxRecurse(...nums.slice(1)) 58 | if (nums[0] > secondNum) return nums[0] 59 | return secondNum 60 | } 61 | 62 | // Write a function not that takes a function and returns the negation of its result 63 | const not = func => (...args) => 64 | !Boolean(func(...args)) 65 | 66 | //Write a function acc that takes a function and an initial value and returns a function that runs the initial function on each argument, accumulating the result 67 | const acc = (func, initial) => (...args) => { 68 | let final = initial; 69 | for (let i of args) { 70 | final = func(final, i); 71 | } 72 | return final; 73 | } 74 | // Write a function accPartial that takes in a function, a start index, and an end index, and returns a function that accumulates a subset of its arguments by applying the given function to all elements between start and end. 75 | const accPartial = (func, start, end) => (...args) => { 76 | const array = args.slice(start, end); 77 | let final = array[0]; 78 | for (let i of array.slice(1)) { 79 | final = func(final, i); 80 | } 81 | args.splice(start, end - start); 82 | args.splice(start, 0, final) 83 | return args 84 | } 85 | 86 | // Write a function accRecurse that does what acc does but uses recursion 87 | const accRecurse = (func, initial) => (...args) => { 88 | if (args.length === 1) { 89 | return func(args[0], initial); 90 | } 91 | return func(accRecurse(func, initial)(...args.slice(1)), args[0]); 92 | } 93 | 94 | const fill = (num) => { 95 | let arr = []; 96 | for(let i=0; i { 101 | if(arr.length === num){ 102 | return arr 103 | }else{ 104 | arr.push(num) 105 | return fillRecurse(num, arr) 106 | } 107 | } 108 | 109 | const set = (...args) => args.filter((arg, index) => args.indexOf(arg) === index); 110 | 111 | const identityf = arg => () => arg 112 | 113 | const addf = a => b => a + b; 114 | 115 | const liftf = fun => a => b => fun(a, b) 116 | 117 | const pure = (x, y) => { 118 | const impure = (x) => { 119 | y++; 120 | z = x * y; 121 | } 122 | impure(x); 123 | return [y, z]; 124 | } 125 | 126 | const curryb = (fun, num) => (num1) => fun(num, num1) 127 | 128 | const curry = (fun, ...rest) => (...any) => fun(...rest.concat(any)) 129 | 130 | const inc = num => addb(num, 1) 131 | 132 | const twiceUnary = fun => num => fun(num, num) 133 | 134 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, inc, twiceUnary, /*doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, */ }; -------------------------------------------------------------------------------- /Solutions/Amarjit_JS_fun.js: -------------------------------------------------------------------------------- 1 | const identity = x => x; 2 | 3 | const addb = (a,b) => a + b; 4 | 5 | const subb = (a,b) => a - b; 6 | 7 | const mulb = (a,b) => a * b; 8 | 9 | const minb = (a,b) => { 10 | if(a { 17 | if(a>b) 18 | return a; 19 | else 20 | return b; 21 | }; 22 | 23 | const add = (...nums) => { 24 | if (nums.length === 0) { 25 | throw new Error("No numbers provided for addition."); 26 | } 27 | let n=nums[0]; 28 | for (let i=1;i { 35 | if (nums.length === 0) { 36 | throw new Error("No numbers provided for subtraction."); 37 | } 38 | let n=nums[0]; 39 | for (let i=1;i { 46 | if (nums.length === 0) { 47 | throw new Error("No numbers provided for multiplication."); 48 | } 49 | let n=nums[0]; 50 | for (let i=1;i { 57 | if (nums.length === 0) { 58 | throw new Error("No numbers provided for minimum."); 59 | } 60 | let n=nums[0]; 61 | for (let i=1;i { 69 | if (nums.length === 0) { 70 | throw new Error("No numbers provided for maximum."); 71 | } 72 | 73 | let n=nums[0]; 74 | for (let i=1;in) 76 | n=nums[i]; 77 | } 78 | return n; 79 | } 80 | 81 | const addRecurse = (...nums) => { 82 | if (nums.length === 0) { 83 | throw new Error("No numbers provided for adding recursively."); 84 | } 85 | 86 | let sum = 0; 87 | for (const num of nums) { 88 | if(Array.isArray(num)) { 89 | sum+=addRecurse(...num); 90 | } 91 | else if (typeof num==='number') { 92 | sum+=num; 93 | } 94 | } 95 | return sum; 96 | } 97 | 98 | const mulRecurse = (...nums) => { 99 | if (nums.length === 0) { 100 | throw new Error("No numbers provided for multiply recursively."); 101 | } 102 | let sum = 1; 103 | for (const num of nums) { 104 | if(Array.isArray(num)) { 105 | sum*=mulRecurse(...num); 106 | } 107 | else if (typeof num==='number') { 108 | sum*=num; 109 | } 110 | } 111 | return sum; 112 | } 113 | 114 | const minRecurse = (...nums) => { 115 | if (nums.length === 0) { 116 | throw new Error("No numbers provided for minimum recursively."); 117 | } 118 | let min = Number.POSITIVE_INFINITY; 119 | for (const num of nums) { 120 | if(Array.isArray(num)) { 121 | const nestedmin = minRecurse(...num); 122 | if(nestedmin { 134 | if (nums.length === 0) { 135 | throw new Error("No numbers provided for maximum recursively."); 136 | } 137 | 138 | let max = Number.NEGATIVE_INFINITY; 139 | for (const num of nums) { 140 | if(Array.isArray(num)) { 141 | const nestedmax = maxRecurse(...num); 142 | if(nestedmax>max) 143 | max=nestedmax; 144 | } 145 | else if (typeof num==='number') { 146 | if(num>max) 147 | max=num; 148 | } 149 | } 150 | return max; 151 | } 152 | 153 | const not = (func)=>{ 154 | return !func(); 155 | } 156 | 157 | const acc = (func, initial) => { 158 | return (...args) => { 159 | let result = initial; 160 | for (const arg of args) { 161 | result = func(result, arg); 162 | } 163 | return result; 164 | }; 165 | }; 166 | 167 | const accPartial = (func, start, end) => { 168 | return (...args) => { 169 | let result = args[start]; 170 | for (let i=start+1;i<=end;i++) { 171 | result = func(result, args[i]); 172 | } 173 | return result; 174 | }; 175 | }; 176 | 177 | const accRecurse = (func, initial) => { 178 | return (...args) => { 179 | if(args.length===0) 180 | return initial; 181 | else { 182 | const [head, ...tail] = args; 183 | return func(initial, head) + accRecurse(func, initial)(...tail); 184 | } 185 | }; 186 | }; 187 | 188 | const fill = (num) => { 189 | const arr = new Array(num); 190 | for (let i=0; i { 197 | if(count===0) { 198 | return arr; 199 | } 200 | arr.push(num); 201 | 202 | return fillRecurse(num,count-1,arr); 203 | }; 204 | 205 | const set=(...args)=>{ 206 | return [...new Set(args)]; 207 | } 208 | 209 | const identityf = (arg)=> { 210 | return()=>arg; 211 | } 212 | 213 | const addf = (a)=>{ 214 | return (b)=> (a+b); 215 | } 216 | 217 | const liftf = (binary)=> { 218 | return (x) => { 219 | return (y) => { 220 | return binary(x,y); 221 | }; 222 | }; 223 | } 224 | 225 | const pure = (x,y)=> { 226 | let newY=y; 227 | let newZ; 228 | const impure = (x)=> { 229 | newY++; 230 | newZ=x*newY; 231 | } 232 | impure(x); 233 | return [newY, newZ]; 234 | } 235 | 236 | const curryb = (binary,a)=> { 237 | return (b)=>binary(a,b); 238 | } 239 | 240 | module.exports = { 241 | identity, 242 | addb, 243 | subb, 244 | mulb, 245 | minb, 246 | maxb, 247 | add, 248 | sub, 249 | mul, 250 | min, 251 | max, 252 | addRecurse, 253 | mulRecurse, 254 | minRecurse, 255 | maxRecurse, 256 | not, 257 | acc, 258 | accPartial, 259 | accRecurse, 260 | fill, 261 | fillRecurse, 262 | set, 263 | identityf, 264 | addf, 265 | liftf, 266 | pure, 267 | curryb 268 | }; -------------------------------------------------------------------------------- /Solutions/BadrEladr.js: -------------------------------------------------------------------------------- 1 | // just starting 2 | 3 | //link 4 | //https://github.com/zero-to-mastery/JS_Fun_Practice 5 | 6 | // identity(x) ⇒ any 7 | // Write a function identity that takes an argument and returns that argument 8 | 9 | const getArg = (arg => arg); 10 | 11 | let argm = 2; 12 | getArg(argm); 13 | 14 | -------------------------------------------------------------------------------- /Solutions/BobTheCool55_Solution.js: -------------------------------------------------------------------------------- 1 | // Write a function max that is generalized for any amount of arguments 2 | 3 | 4 | const max = ((...nums) => { 5 | return nums.reduce((aco,num) => { 6 | if (aco>num) { 7 | return aco; 8 | } 9 | else { 10 | return num; 11 | }; 12 | }, 0) 13 | }) 14 | 15 | 16 | // Write a function mulRecurse that is the generalized mul function but uses recursion 17 | 18 | const mulRecurse = (...nums) => { 19 | if (nums.length === 1) return nums[0] 20 | return nums.pop() * mulRecurse(...nums); 21 | } 22 | 23 | 24 | // Write a function minRecurse that is the generalized min function but uses recursion 25 | 26 | 27 | const minRecurse = (...nums) => { 28 | if (nums.length === 1) { 29 | return nums[0]; 30 | } 31 | if (nums[0] < nums[1]) { 32 | nums.splice(1, 1) 33 | } 34 | else { 35 | nums.splice(0, 1) 36 | } 37 | return minRecurse(...nums); 38 | } 39 | 40 | 41 | //Write a function fill that takes a number and returns an array with that many numbers equal to the given number 42 | 43 | 44 | const fill1 = (num) => { 45 | arr = []; 46 | for (let i=0; i { 56 | if (arr.length === num) return arr; 57 | else { 58 | arr.push(num) 59 | return fill(num,arr) 60 | } 61 | } 62 | 63 | // Write a function set that is given a list of arguments and returns an array with all duplicates removed 64 | 65 | 66 | const set = (...nums) => { 67 | let output = []; 68 | for (let i=0; i argument; 3 | 4 | //Write a binary function addb that takes two numbers and returns their sum 5 | const addb = (a, b) => a + b; 6 | 7 | // Write a binary function subb that takes two numbers and returns their difference 8 | const subb = (a, b) => a - b; 9 | 10 | // Write a binary function mulb that takes two numbers and returns their product 11 | const mulb = (a, b) => a*b; 12 | 13 | // Write a binary function minb that takes two numbers and returns the smaller one 14 | const minb = (a, b) => a < b ? a : b; 15 | 16 | // Write a binary function maxb that takes two numbers and returns the larger one 17 | const maxb = (a, b) => a > b ? a : b; 18 | 19 | // Write a function add that is generalized for any amount of arguments 20 | const add = (...nums) => nums.reduce((a, b)=>a+b) 21 | 22 | // Write a function sub that is generalized for any amount of arguments 23 | const sub = (...nums) => nums.reduce((a, b)=>a-b) 24 | 25 | //Write a function mul that is generalized for any amount of arguments 26 | const mul = (...nums) => nums.reduce((a, b)=>a*b , 1) 27 | 28 | // Write a function min that is generalized for any amount of arguments 29 | const min = (...nums) => nums.reduce((a, b)=> Math.min(a, b)) 30 | 31 | // Write a function max that is generalized for any amount of arguments 32 | const max = (...nums) => nums.reduce((a, b)=> Math.max(a, b)) 33 | 34 | // Write a function identityf that takes an argument and returns a function that returns that argument 35 | const identityf = (x) => { 36 | const inside = () => { 37 | return x; 38 | } 39 | return inside; 40 | } 41 | 42 | // Write a function addf that adds from two invocations 43 | const addf = (a) => (b) => a + b; 44 | 45 | // Write a function liftf that takes a binary function, and makes it callable with two invocations 46 | const liftf = (f) => (a) => (b) => f(a,b); 47 | 48 | 49 | module.exports = { 50 | identity, 51 | addb, 52 | subb, 53 | mulb, 54 | minb, 55 | maxb, 56 | add, 57 | sub, 58 | mul, 59 | min, 60 | max, 61 | addRecurse, 62 | mulRecurse, 63 | minRecurse, 64 | maxRecurse, 65 | not, 66 | acc, 67 | accPartial, 68 | accRecurse, 69 | fill, 70 | fillRecurse, 71 | set, 72 | identityf, 73 | addf, 74 | liftf, 75 | pure, 76 | curryb, 77 | curry, 78 | inc, 79 | twiceUnary, 80 | doubl, 81 | square, 82 | twice, 83 | reverseb, 84 | reverse, 85 | composeuTwo, 86 | composeu, 87 | composeb, 88 | composeTwo, 89 | compose, 90 | limitb, 91 | limit, 92 | genFrom, 93 | genTo, 94 | genFromTo, 95 | elementGen, 96 | element, 97 | collect, 98 | filter, 99 | filterTail, 100 | concatTwo, 101 | concat, 102 | concatTail, 103 | gensymf, 104 | gensymff, 105 | fibonaccif, 106 | counter, 107 | revocableb, 108 | revocable, 109 | extract, 110 | m, 111 | addmTwo, 112 | addm, 113 | liftmbM, 114 | liftmb, 115 | liftm, 116 | exp, 117 | expn, 118 | addg, 119 | liftg, 120 | arrayg, 121 | continuizeu, 122 | continuize, 123 | vector, 124 | exploitVector, 125 | vectorSafe, 126 | pubsub, 127 | mapRecurse, 128 | filterRecurse, 129 | 130 | }; -------------------------------------------------------------------------------- /Solutions/Indrajith_solution.js: -------------------------------------------------------------------------------- 1 | const identity = (x) => x; 2 | 3 | const addb = (a, b) => a + b; 4 | 5 | const subb = (a, b) => a - b; 6 | 7 | const mulb = (a, b) => a * b; 8 | 9 | const minb = (a, b) => Math.min(a, b); 10 | 11 | const maxb = (a, b) => Math.max(a, b); 12 | 13 | const add = (...nums) => nums.reduce((a, b) => a + b, 0); 14 | 15 | const sub = (...nums) => nums.reduce((a, b) => a - b); 16 | 17 | const mul = (...nums) => nums.reduce((a, b) => a * b); 18 | 19 | const min = (...nums) => nums.reduce((a, b) => (a < b ? a : b)); 20 | 21 | const max = (...nums) => nums.reduce((a, b) => (a > b ? a : b)); 22 | 23 | module.exports = { 24 | identity, 25 | addb, 26 | subb, 27 | mulb, 28 | minb, 29 | maxb, 30 | add, 31 | sub, 32 | mul, 33 | min, 34 | max, 35 | }; 36 | -------------------------------------------------------------------------------- /Solutions/Krios_Solutions.js: -------------------------------------------------------------------------------- 1 | const identity = (x) => x; 2 | 3 | const addb = (a,b) => a+b; 4 | 5 | const subb = (a,b) => a-b; 6 | 7 | const mulb = (a,b) => a*b; 8 | 9 | const minb = (a,b) => (a < b) ? a : b; 10 | 11 | const maxb = (a,b) => (a > b) ? a : b; 12 | 13 | //generalized for any number of parameters creates an array of value 14 | //acc starts at the first element of the array 15 | const add = (...nums) => nums.reduce((acc, value) => acc + value); 16 | console.log(add(1,2,3,4)); 17 | 18 | const sub = (...nums) => nums.reduce((acc,value) => acc - value); 19 | 20 | const mul = (...nums) => nums.reduce((acc, value) => acc * value); 21 | 22 | const min = (...nums) => nums.reduce((acc, value) => (acc < value ? acc : acc = value)); 23 | 24 | const max = (...nums) => nums.reduce((acc, value) => (acc > value ? acc : acc = value)); 25 | 26 | 27 | onsole.log(acc(addb(1, 2, 4), 1)); 28 | 29 | 30 | 31 | 32 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, 33 | maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, 34 | inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, 35 | limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, 36 | gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, 37 | liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, }; -------------------------------------------------------------------------------- /Solutions/Maurice972_solutions.js: -------------------------------------------------------------------------------- 1 | 2 | //Maurice972 solutions 3 | 4 | //Write a function identity that takes an argument and returns that argument 5 | function identity(x) { 6 | return x 7 | }; 8 | 9 | // Write a binary function addb that takes two numbers and returns their sum 10 | function addb(a,b) { 11 | return a + b 12 | }; 13 | 14 | // Write a binary function subb that takes two numbers and returns their difference 15 | function subb(a,b) { 16 | return a - b 17 | }; 18 | 19 | // Write a binary function mulb that takes two numbers and returns their product 20 | function mulb(a,b) { 21 | return a * b 22 | }; 23 | 24 | // Write a binary function minb that takes two numbers and returns the smaller one 25 | function minb(a,b) { 26 | if (a > b) { 27 | return b 28 | } else { 29 | return a 30 | } 31 | }; 32 | 33 | // Write a binary function maxb that takes two numbers and returns the larger one 34 | const maxb = (a,b) => a > b ? a : b; 35 | 36 | // Write a function add that is generalized for any amount of arguments 37 | function add(...nums) { 38 | return nums.reduce((a,b) => a + b) 39 | }; 40 | 41 | // Write a function sub that is generalized for any amount of arguments 42 | function sub(...nums) { 43 | return nums.reduce((a,b) => a - b) 44 | }; 45 | 46 | // Write a function mul that is generalized for any amount of arguments 47 | function sub(...nums) { 48 | return nums.reduce((a,b) => a * b) 49 | }; 50 | 51 | // Write a function min that is generalized for any amount of arguments 52 | function min(...nums) { 53 | return nums.reduce((a,b) => a > b ? a : b) 54 | }; 55 | 56 | // Write a function max that is generalized for any amount of arguments 57 | 58 | function max(...nums) { 59 | return nums.reduce((a,b) => a < b ? a : b) 60 | }; 61 | 62 | // Write a function addRecurse that is the generalized add function but uses recursion 63 | 64 | function addRecurse(...nums) { 65 | if (nums.length < 1) 66 | return 0 67 | return nums[0] + addRecurse(...nums.slice(1)) 68 | }; 69 | 70 | // Write a function mulRecurse that is the generalized mul function but uses recursion 71 | 72 | function mulRecurse(...nums) { 73 | if (nums.length < 1) 74 | return 0 75 | return nums[0] * mulRecurse(...nums.slice(1)) 76 | }; 77 | 78 | module.exports = { 79 | identity, 80 | addb, 81 | subb, 82 | mulb, 83 | minb, 84 | maxb, 85 | add, 86 | sub, 87 | mul, 88 | min, 89 | max, 90 | addRecurse, 91 | mulRecurse, 92 | // minRecurse, 93 | // maxRecurse, 94 | // not, 95 | // acc, 96 | // accPartial, 97 | // accRecurse, 98 | // fill, 99 | // fillRecurse, 100 | // set, 101 | // identityf, 102 | // addf, 103 | // liftf, 104 | // pure, 105 | // curryb, 106 | // curry, 107 | // inc, 108 | // twiceUnary, 109 | // doubl, 110 | // square, 111 | // twice, 112 | // reverseb, 113 | // reverse, 114 | // composeuTwo, 115 | // composeu, 116 | // composeb, 117 | // composeTwo, 118 | // compose, 119 | // limitb, 120 | // limit, 121 | // genFrom, 122 | // genTo, 123 | // genFromTo, 124 | // elementGen, 125 | // element, 126 | // collect, 127 | // filter, 128 | // filterTail, 129 | // concatTwo, 130 | // concat, 131 | // concatTail, 132 | // gensymf, 133 | // gensymff, 134 | // fibonaccif, 135 | // counter, 136 | // revocableb, 137 | // revocable, 138 | // extract, 139 | // m, 140 | // addmTwo, 141 | // addm, 142 | // liftmbM, 143 | // liftmb, 144 | // liftm, 145 | // exp, 146 | // expn, 147 | // addg, 148 | // liftg, 149 | // arrayg, 150 | // continuizeu, 151 | // continuize, 152 | // vector, 153 | // exploitVector, 154 | // vectorSafe, 155 | // pubsub, 156 | // mapRecurse, 157 | // filterRecurse, 158 | }; 159 | -------------------------------------------------------------------------------- /Solutions/Mohamed_Cheour_Solutions.js: -------------------------------------------------------------------------------- 1 | function identity(x){ 2 | return x 3 | } 4 | 5 | 6 | module.exports = { 7 | identity, 8 | // addb, 9 | // subb, 10 | // mulb, 11 | // minb, 12 | // maxb, 13 | // add, 14 | // sub, 15 | // mul, 16 | // min, 17 | // max, 18 | // addRecurse, 19 | // mulRecurse, 20 | // minRecurse, 21 | // maxRecurse, 22 | // not, 23 | // acc, 24 | // accPartial, 25 | // accRecurse, 26 | // fill, 27 | // fillRecurse, 28 | // set, 29 | // identityf, 30 | // addf, 31 | // liftf, 32 | // pure, 33 | // curryb, 34 | // curry, 35 | // inc, 36 | // twiceUnary, 37 | // doubl, 38 | // square, 39 | // twice, 40 | // reverseb, 41 | // reverse, 42 | // composeuTwo, 43 | // composeu, 44 | // composeb, 45 | // composeTwo, 46 | // compose, 47 | // limitb, 48 | // limit, 49 | // genFrom, 50 | // genTo, 51 | // genFromTo, 52 | // elementGen, 53 | // element, 54 | // collect, 55 | // filter, 56 | // filterTail, 57 | // concatTwo, 58 | // concat, 59 | // concatTail, 60 | // gensymf, 61 | // gensymff, 62 | // fibonaccif, 63 | // counter, 64 | // revocableb, 65 | // revocable, 66 | // extract, 67 | // m, 68 | // addmTwo, 69 | // addm, 70 | // liftmbM, 71 | // liftmb, 72 | // liftm, 73 | // exp, 74 | // expn, 75 | // addg, 76 | // liftg, 77 | // arrayg, 78 | // continuizeu, 79 | // continuize, 80 | // vector, 81 | // exploitVector, 82 | // vectorSafe, 83 | // pubsub, 84 | // mapRecurse, 85 | // filterRecurse, 86 | }; -------------------------------------------------------------------------------- /Solutions/My-Solutions-ML.js: -------------------------------------------------------------------------------- 1 | /* 1.- Identity(x) 2 | Write a function identity that takes an argument 3 | and returns that argument*/ 4 | 5 | const identity = (x) => x; 6 | 7 | /* 2.- addb(a, b) ⇒ number 8 | Write a binary function addb that takes two 9 | numbers and returns their sum */ 10 | 11 | const addb = (a,b) => a+b; 12 | 13 | /* 3.- subb(a, b) ⇒ number 14 | Write a binary function subb that takes two 15 | numbers and returns their difference */ 16 | 17 | const subb = (a,b) => a-b; 18 | 19 | /* 4.- mulb(a, b) ⇒ number 20 | Write a binary function mulb that takes two 21 | numbers and returns their product */ 22 | 23 | const mulb = (a,b) => a*b; 24 | 25 | /* 5.- minb(a, b) ⇒ number 26 | Write a binary function minb that takes two 27 | numbers and returns the smaller one */ 28 | 29 | const minb = (a,b) => a>b ? b:a; 30 | 31 | /* 6.-maxb(a, b) ⇒ number 32 | Write a binary function maxb that takes two 33 | numbers and returns the larger one */ 34 | 35 | const maxb = (a,b) => a>b ? a:b; 36 | 37 | /* 7.- add(...nums) ⇒ number 38 | Write a function add that is generalized 39 | for any amount of arguments */ 40 | 41 | const add = (...numbers) => 42 | numbers.reduce((Acumulator,CurrentValue) => 43 | Acumulator += CurrentValue); 44 | 45 | /* 8.- sub(...nums) ⇒ number 46 | Write a function sub that is generalized 47 | for any amount of arguments */ 48 | 49 | const sub = (...numbers) => 50 | numbers.reduce((Acumulator,CurrentValue) => 51 | Acumulator -= CurrentValue); 52 | 53 | /* 9.- mul(...nums) ⇒ number 54 | Write a function mul that is generalized 55 | for any amount of arguments */ 56 | 57 | const mul = (...numbers) => 58 | numbers.reduce((Acumulator,CurrentValue) => 59 | Acumulator *= CurrentValue); 60 | 61 | /* 10.- min(...nums) ⇒ number 62 | Write a function min that is generalized 63 | for any amount of arguments */ 64 | 65 | const min = (...numbers) => 66 | numbers.reduce((Acumulator,CurrentValue) => 67 | Acumulator = Acumulator < CurrentValue ? Acumulator:CurrentValue); 68 | 69 | /* 11.- max(...nums) ⇒ number 70 | Write a function max that is generalized 71 | for any amount of arguments */ 72 | 73 | const max = (...numbers) => 74 | numbers.reduce((Acumulator,CurrentValue) => 75 | Acumulator = Acumulator > CurrentValue ? Acumulator:CurrentValue); 76 | 77 | /* 12.- addRecurse(...nums) ⇒ number 78 | Write a function addRecurse that is the 79 | generalized add function but uses recursion */ 80 | 81 | const addRecurse = (...numbers) => { 82 | if (numbers.length < 1) //base case 83 | return 0 84 | return numbers[0] + addRecurse(...numbers.slice(1)) 85 | } 86 | //Took the solution from the file 'my-solutions-GM.js' 87 | 88 | /* 13.- mulRecurse(...nums) ⇒ number 89 | Write a function mulRecurse that is the 90 | generalized mul function but uses recursion */ 91 | 92 | const mulRecurse = (...numbers) => { 93 | if (numbers.length == 1) 94 | return numbers[0] 95 | return numbers[0] * mulRecurse(...numbers.slice(1)) 96 | } 97 | 98 | /* 14.- minRecurse(...nums) ⇒ number 99 | Write a function minRecurse that is the 100 | generalized min function but uses recursion */ 101 | 102 | const minRecurse = (...numbers) => { 103 | if (numbers.length == 1) 104 | return console.log(numbers[0]) 105 | 106 | if (numbers[0] < numbers[1]) 107 | numbers.splice(1,1); 108 | else 109 | numbers.splice(0,0); 110 | 111 | return minRecurse(...numbers); 112 | } 113 | 114 | /* 15.- maxRecurse(...nums) ⇒ number 115 | Write a function maxRecurse that is the 116 | generalized max function but uses recursion */ 117 | 118 | const maxRecurse = (...numbers) => { 119 | if (numbers.length == 1) 120 | return console.log(numbers[0]); 121 | 122 | if (numbers[0] > numbers[1]) 123 | numbers.splice(1,1); 124 | else 125 | numbers.splice(0,1); 126 | 127 | return maxRecurse(...numbers); 128 | } 129 | 130 | /* 16.- 131 | 132 | -------------------------------------------------------------------------------- /Solutions/MySolutions_ON.js: -------------------------------------------------------------------------------- 1 | //Write a function identity that takes an argument and returns that argument 2 | 3 | const identity = (x) => { 4 | return x; 5 | } 6 | 7 | console.log(identity(3)); 8 | 9 | //Write a binary function addb that takes two numbers and returns their sum 10 | const addb = (a,b) => { 11 | return a+b; 12 | } 13 | 14 | console.log(addb(3,5)); 15 | 16 | //Write a binary function subb that takes two numbers and returns their difference 17 | 18 | const subb = (a,b) => { 19 | return a-b; 20 | } 21 | 22 | console.log(subb(3,5)); 23 | 24 | //Write a binary function mulb that takes two numbers and returns their product 25 | 26 | const mulb = (a,b) => { 27 | return a*b; 28 | } 29 | 30 | console.log(mulb(3,5)); 31 | 32 | //Write a binary function minb that takes two numbers and returns the smaller one 33 | 34 | const minb = (a,b) => { 35 | if (a { 46 | if (a>b){ 47 | return a; 48 | } 49 | return b; 50 | } 51 | 52 | console.log(maxb(3,8)); 53 | 54 | //Write a function add that is generalized for any amount of arguments 55 | 56 | const add = (...nums) => { 57 | let sum = 0; 58 | for (item of nums){ 59 | sum += item; 60 | } 61 | return sum; 62 | } 63 | 64 | console.log(add(3,4,5,6)); 65 | 66 | 67 | //Write a function sub that is generalized for any amount of arguments 68 | 69 | const sub = (...nums) => { 70 | let diff = 0; 71 | for (item of nums){ 72 | diff -= item; 73 | } 74 | return diff; 75 | } 76 | 77 | console.log(sub(3,4,5,6)); 78 | 79 | //Write a function mul that is generalized for any amount of arguments 80 | 81 | const mul = (...nums) => { 82 | let product = 0; 83 | for (item of nums){ 84 | product *= item; 85 | } 86 | return product; 87 | } 88 | 89 | console.log(mul(3,4,5,6)); 90 | 91 | //Write a function min that is generalized for any amount of arguments 92 | 93 | const min = (...nums) => { 94 | let min = nums[0]; 95 | for (item of nums){ 96 | if(item { 108 | let max = nums[0]; 109 | for (item of nums){ 110 | if(item>max){ 111 | max = item; 112 | } 113 | } 114 | return max; 115 | } 116 | 117 | console.log(max(3,4,5,6)); 118 | 119 | //Write a function addRecurse that is the generalized add function but uses recursion 120 | 121 | const addRecurse = (...nums) => { 122 | if (nums.length<=0){ 123 | return 0; 124 | } 125 | return nums[0] + (addRecurse(...nums.slice(1))); 126 | } 127 | 128 | //Write a function mulRecurse that is the generalized mul function but uses recursion 129 | 130 | const mulRecurse = (...nums) => { 131 | if (nums.length<=0){ 132 | return 1; 133 | } 134 | return nums[0] + (mulRecurse(...nums.slice(1))); 135 | } 136 | 137 | //Write a function minRecurse that is the generalized min function but uses recursion 138 | 139 | const minRecurse = (...nums) => { 140 | if(nums.length>1){ 141 | if (nums[0] { 154 | if(nums.length>1){ 155 | if (nums[0]>maxRecurse(...nums.slice(1))){ 156 | return nums[0]; 157 | } 158 | return maxRecurse(...nums.slice(1)); 159 | } 160 | else{ 161 | return nums[0]; 162 | } 163 | } 164 | 165 | //Write a function not that takes a function and returns the negation of its result 166 | 167 | const not = (func) => { 168 | return (...args) => !func(...args); 169 | } 170 | 171 | //Write a function acc that takes a function and an initial value and returns a function that runs the initial function on each argument, accumulating the result 172 | 173 | const acc = (func, initial) => { 174 | return (...args) => { 175 | for (item of args){ 176 | initial += func(item); 177 | } 178 | return initial; 179 | } 180 | } 181 | 182 | //Write a function accPartial that takes in a function, a start index, and an end index, and returns a function that accumulates a subset of its arguments by applying the given function to all elements between start and end. 183 | 184 | const accPartial = (func, start, end) => { 185 | let accum = 0; 186 | return (...args) => { 187 | for (let i = start; i< start+end; i++){ 188 | accum += func(args[i]); 189 | } 190 | return accum 191 | } 192 | } 193 | 194 | //Write a function fill that takes a number and returns an array with that many numbers equal to the given number 195 | 196 | const fill = (num) => { 197 | let nums = []; 198 | for (let i=0; i { 207 | if(list.length===num){ 208 | return list; 209 | } 210 | else{ 211 | list.push(num); 212 | return fillRecurse(num,list); 213 | } 214 | }; 215 | 216 | //Write a function set that is given a list of arguments and returns an array with all duplicates removed 217 | 218 | const set = (...args) => { 219 | let sett=[]; 220 | for (item of args){ 221 | if (sett.includes(item)){ 222 | 223 | } 224 | else { 225 | sett.push(item) 226 | } 227 | } 228 | return sett; 229 | } 230 | 231 | //Write a function identityf that takes an argument and returns a function that returns that argument 232 | 233 | const identityf = (x) =>{ 234 | return (x) => {x}; 235 | } 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | -------------------------------------------------------------------------------- /Solutions/OddOrEven.js: -------------------------------------------------------------------------------- 1 | function oddOrEven (a){ 2 | if ((a%2)===0){ 3 | console.log("This number is even"); 4 | } 5 | else if ((a%2)===1) { 6 | console.log(" This number is odd"); 7 | } 8 | 9 | else { 10 | console.log("Write a valid number."); 11 | } 12 | } -------------------------------------------------------------------------------- /Solutions/OkelloSam21_solutions.json: -------------------------------------------------------------------------------- 1 | //Write a function `identity` that takes an argument and returns that argument. 2 | ``` 3 | const identity = (x) => x 4 | 5 | ``` 6 | //Write a binary function `adb` that takes two numbers and returns their sum 7 | ``` 8 | const adb = ( a,b) => (a + b) 9 | 10 | ``` 11 | 12 | //Write a binary function subb that takes two numbers and returns their difference 13 | ``` 14 | const sub = (a,b) => (a - b) 15 | 16 | ``` 17 | 18 | //Write a binary function `mulb` that takes two numbers and returns their product 19 | 20 | ``` 21 | const mulb = (a,b) => (a * b); 22 | 23 | ``` 24 | 25 | //Write a binary function `minb` that takes two numbers and returns the smaller one 26 | 27 | ``` 28 | const sub = (a,b) => a < b ? a : b; 29 | 30 | ``` 31 | 32 | //Write a binary function maxb that takes two numbers and returns the larger one 33 | 34 | ``` 35 | const sub = (a,b) => a > b ? a : b; 36 | 37 | ``` 38 | //Write a function add that is generalized for any amount of arguments 39 | 40 | ``` 41 | const add = (...nums) => nums.reduce((a , b)=>a+b) 42 | 43 | ``` 44 | //Write a function sub that is generalized for any amount of arguments 45 | ``` 46 | const add = (...nums) => nums.reduce((a , b)=>a+b) 47 | 48 | ``` 49 | 50 | //Write a function mul that is generalized for any amount of arguments 51 | ``` 52 | const add = (...nums) => nums.reduce((a , b)=>a - b) 53 | 54 | ``` 55 | 56 | //Write a function min that is generalized for any amount of arguments 57 | ``` 58 | const add = (...nums) => nums.reduce((a, b)=>Math.min(a,b)) 59 | 60 | ``` 61 | 62 | //Write a function max that is generalized for any amount of arguments 63 | ``` 64 | const add = (...nums) => nums.reduce((a, b)=>Math.max(a,b)) 65 | 66 | ``` 67 | -------------------------------------------------------------------------------- /Solutions/Osvaldo_Solutions.js: -------------------------------------------------------------------------------- 1 | const identity = (arg) => arg; 2 | 3 | const addb = (a, b) => a + b; 4 | 5 | const subb = (a, b) => a - b; 6 | 7 | const mulb = (a, b) => a * b; 8 | 9 | const minb = (a, b) => Math.min(a, b); 10 | 11 | const minb = (a, b) => (a < b ? a : b); 12 | 13 | const maxb = (a, b) => Math.max(a, b); 14 | // or 15 | const maxb = (a, b) => (a > b ? a : b); 16 | 17 | const add = (...nums) => nums.reduce((acc, cur) => acc + cur); 18 | 19 | const sub = (...nums) => nums.reduce((acc, cur) => acc - cur); 20 | 21 | const mul = (...nums) => nums.reduce((acc, cur) => acc * cur); 22 | 23 | const min = (...nums) => Math.min(...nums); 24 | 25 | const max = (...nums) => Math.max(...nums); 26 | 27 | const addRecurse = (...nums) => { 28 | if (nums.length === 1) return nums[0]; 29 | return nums.pop() + addRecurse(...nums); 30 | }; 31 | 32 | const mulRecurse = (...nums) => { 33 | if (nums.length === 1) return nums[0]; 34 | return nums.pop() * mulRecurse(...nums); 35 | }; 36 | 37 | module.exports = { 38 | identity, 39 | addb, 40 | subb, 41 | mulb, 42 | minb, 43 | maxb, 44 | add, 45 | sub, 46 | mul, 47 | min, 48 | max, 49 | addRecurse, 50 | mulRecurse, 51 | }; 52 | -------------------------------------------------------------------------------- /Solutions/RavisSolution.js: -------------------------------------------------------------------------------- 1 | const everyone = ['dory' , 'fikas' ,'maria' ,'jsin','lave','binap']; 2 | function findsin(array){ 3 | for(i=0;i { 3 | return x 4 | } 5 | 6 | // Write a binary function addb that takes two numbers and returns their sum 7 | const addb = (a, b) => { 8 | return a + b; 9 | } 10 | 11 | // Write a binary function subb that takes two numbers and returns their difference 12 | const subb = (a, b) => { 13 | return a - b; 14 | } 15 | 16 | // Write a binary function mulb that takes two numbers and returns their product 17 | const mulb = (a, b) => { 18 | return a * b; 19 | } 20 | 21 | // Write a binary function minb that takes two numbers and returns the smaller one 22 | const minb = (a, b) => { 23 | if (a < b) { 24 | return a; 25 | } else { 26 | return b; 27 | } 28 | } 29 | 30 | // Write a binary function maxb that takes two numbers and returns the larger one 31 | const maxb = (a, b) => { 32 | if (a > b) { 33 | return a; 34 | } else { 35 | return b; 36 | } 37 | } 38 | 39 | module.exports = { 40 | identity, 41 | addb, 42 | subb, 43 | mulb, 44 | minb, 45 | maxb 46 | }; 47 | -------------------------------------------------------------------------------- /Solutions/adrianSolution.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | const identity = (x) => { 3 | return x; 4 | } 5 | 6 | identity(10); 7 | 8 | // Write a binary function addb that takes two numbers and returns their sum 9 | const addb = (a, b) => { 10 | return a + b; 11 | } 12 | 13 | addb(3, 4); 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | module.exports = { 36 | identity, 37 | addb, 38 | subb, 39 | mulb, 40 | minb, 41 | maxb, 42 | add, 43 | sub, 44 | mul, 45 | min, 46 | max, 47 | addRecurse, 48 | mulRecurse, 49 | minRecurse, 50 | maxRecurse, 51 | not, 52 | acc, 53 | accPartial, 54 | accRecurse, 55 | fill, 56 | fillRecurse, 57 | set, 58 | identityf, 59 | addf, 60 | liftf, 61 | pure, 62 | curryb, 63 | curry, 64 | inc, 65 | twiceUnary, 66 | doubl, 67 | square, 68 | twice, 69 | reverseb, 70 | reverse, 71 | composeuTwo, 72 | composeu, 73 | composeb, 74 | composeTwo, 75 | compose, 76 | limitb, 77 | limit, 78 | genFrom, 79 | genTo, 80 | genFromTo, 81 | elementGen, 82 | element, 83 | collect, 84 | filter, 85 | filterTail, 86 | concatTwo, 87 | concat, 88 | concatTail, 89 | gensymf, 90 | gensymff, 91 | fibonaccif, 92 | counter, 93 | revocableb, 94 | revocable, 95 | extract, 96 | m, 97 | addmTwo, 98 | addm, 99 | liftmbM, 100 | liftmb, 101 | liftm, 102 | exp, 103 | expn, 104 | addg, 105 | liftg, 106 | arrayg, 107 | continuizeu, 108 | continuize, 109 | vector, 110 | exploitVector, 111 | vectorSafe, 112 | pubsub, 113 | mapRecurse, 114 | filterRecurse, 115 | }; -------------------------------------------------------------------------------- /Solutions/alex_solutions.js: -------------------------------------------------------------------------------- 1 | // identity(x) ⇒ any 2 | // Write a function identity that takes an argument and returns that argument 3 | 4 | const identity = (x) => x; 5 | 6 | // addb(a, b) ⇒ number 7 | // Write a binary function addb that takes two numbers and returns their sum 8 | 9 | const addb = (a, b) => a + b; 10 | 11 | // subb(a, b) ⇒ number 12 | // Write a binary function subb that takes two numbers and returns their difference 13 | 14 | const subb = (a, b) => a - b; 15 | 16 | // mulb(a, b) ⇒ number 17 | // Write a binary function mulb that takes two numbers and returns their product 18 | 19 | const mulb = (a, b) => a * b; 20 | 21 | // minb(a, b) ⇒ number 22 | // Write a binary function minb that takes two numbers and returns the smaller one 23 | 24 | const minb = (a, b) => (a < b ? a : b); 25 | 26 | // maxb(a, b) ⇒ number 27 | // Write a binary function maxb that takes two numbers and returns the larger one 28 | 29 | const maxb = (a, b) => (a > b ? a : b); 30 | 31 | // add(...nums) ⇒ number 32 | // Write a function add that is generalized for any amount of arguments 33 | 34 | const add = (...nums) => nums.reduce((acc, curr) => acc + curr, 0); 35 | 36 | // sub(...nums) ⇒ number 37 | // Write a function sub that is generalized for any amount of arguments 38 | 39 | const sub = (...nums) => nums.reduce((acc, curr) => acc - curr, 0); 40 | 41 | // mul(...nums) ⇒ number 42 | // Write a function mul that is generalized for any amount of arguments 43 | 44 | const mul = (...nums) => nums.reduce((acc, curr) => acc * curr, 1); 45 | 46 | // min(...nums) ⇒ number 47 | // Write a function min that is generalized for any amount of arguments 48 | 49 | const min = (...nums) => nums.reduce((acc, curr) => (acc < curr ? acc : curr)); 50 | 51 | // max(...nums) ⇒ number 52 | // Write a function max that is generalized for any amount of arguments 53 | 54 | const max = (...nums) => nums.reduce((acc, curr) => (acc > curr ? acc : curr)); 55 | 56 | // addRecurse(...nums) ⇒ number 57 | // Write a function addRecurse that is the generalized add function but uses recursion 58 | 59 | const addRecurse = (...nums) => { 60 | if (nums.length === 0) { 61 | return 0; 62 | } 63 | return nums[0] + addRecurse(...nums.slice(1)); 64 | }; 65 | 66 | // mulRecurse(...nums) ⇒ number 67 | // Write a function mulRecurse that is the generalized mul function but uses recursion 68 | 69 | const mulRecurse = (...nums) => { 70 | if (nums.length === 0) { 71 | return 1; 72 | } 73 | return nums[0] * mulRecurse(...nums.slice(1)); 74 | }; 75 | 76 | // minRecurse(...nums) ⇒ number 77 | // Write a function minRecurse that is the generalized min function but uses recursion 78 | 79 | const minRecurse = (...nums) => { 80 | if (nums.length === 0) { 81 | return Infinity; 82 | } 83 | return nums[0] < minRecurse(...nums.slice(1)) 84 | ? nums[0] 85 | : minRecurse(...nums.slice(1)); 86 | }; 87 | 88 | // maxRecurse(...nums) ⇒ number 89 | // Write a function maxRecurse that is the generalized max function but uses recursion 90 | 91 | const maxRecurse = (...nums) => { 92 | if (nums.length === 0) { 93 | return -Infinity; 94 | } 95 | return nums[0] > maxRecurse(...nums.slice(1)) 96 | ? nums[0] 97 | : maxRecurse(...nums.slice(1)); 98 | }; 99 | 100 | // not(func) ⇒ function 101 | // Write a function not that takes a function and returns the negation of its result 102 | 103 | const not = 104 | (func) => 105 | (...args) => 106 | !func(...args); 107 | 108 | // acc(func, initial) ⇒ function 109 | // Write a function acc that takes a function and an initial value and returns a function that runs the initial function on each argument, accumulating the result 110 | 111 | const acc = 112 | (func, initial) => 113 | (...args) => 114 | args.reduce(func, initial); 115 | 116 | // accPartial(func, start, end) ⇒ function 117 | // Write a function accPartial that takes in a function, a start index, and an end index, and returns a function that accumulates a subset of its arguments by applying the given function to all elements between start and end. 118 | 119 | // accRecurse(func, initial) ⇒ function 120 | // Write a function accRecurse that does what acc does but uses recursion 121 | 122 | const accRecurse = (func, initial) => { 123 | return function (...args) { 124 | if (args.length === 0) { 125 | return initial; 126 | } 127 | return func(args[0], accRecurse(func, initial)(...args.slice(1))); 128 | }; 129 | }; 130 | 131 | // fill(num) ⇒ array 132 | // Write a function fill that takes a number and returns an array with that many numbers equal to the given number 133 | 134 | const fill = (num) => { 135 | const arr = []; 136 | for (let i = 0; i < num; i++) { 137 | arr.push(num); 138 | } 139 | return arr; 140 | }; 141 | 142 | // fillRecurse(num) ⇒ array 143 | // Write a function fillRecurse that does what fill does but uses recursion 144 | 145 | const fillRecurse = (num) => { 146 | if (num === 0) { 147 | return []; 148 | } 149 | return [num].concat(fillRecurse(num - 1)); 150 | }; 151 | 152 | // set(...args) ⇒ array 153 | // Write a function set that is given a list of arguments and returns an array with all duplicates removed 154 | 155 | const set = (...args) => { 156 | const arr = []; 157 | for (let i = 0; i < args.length; i++) { 158 | if (!arr.includes(args[i])) { 159 | arr.push(args[i]); 160 | } 161 | } 162 | return arr; 163 | }; 164 | -------------------------------------------------------------------------------- /Solutions/arham2002.js: -------------------------------------------------------------------------------- 1 | 2 | const identity = (x) => { 3 | return x; 4 | } 5 | 6 | const addb = (a,b) => { 7 | return a+b; 8 | } 9 | 10 | function subb(a,b) { 11 | return a-b; 12 | } 13 | 14 | const mulb = (a,b) => { 15 | return a*b; 16 | } 17 | 18 | const min = (a,b) => { 19 | if (a { 25 | if (a>b) { 26 | return a; 27 | } else return b; 28 | } 29 | 30 | const add = (...arguments) => { 31 | let sum = 0; 32 | for (let i=0; i { 39 | let diff = 0; 40 | for (let i=0; i { 47 | let prod = 0; 48 | for (let i=0; i { 55 | let num = arguments[0]; 56 | for (let i=0; i { 66 | let num = arguments[0]; 67 | for (let i=0; iarguments[i]) { 69 | num = arguments{i}; 70 | } 71 | 72 | } 73 | return num; 74 | }; 75 | 76 | const addRecurse = (...args) => { 77 | if (args.length === 1) 78 | return Number(args[0]); 79 | else 80 | return Number(args[args.length-1]) + addRecurse(...args.slice(0,-1)); 81 | }; 82 | 83 | const mulRecurse = (...args) => { 84 | if (args.length === 1) 85 | return Number(args[0]); 86 | else 87 | return Number(args[args.length-1]) * addRecurse(...args.slice(0,-1)); 88 | }; 89 | 90 | const minRecurse = (...args) => { 91 | if (args.length === 1) 92 | return Number(args[0]); 93 | else 94 | return Number(args[args.length-1]) < addRecurse(...args.slice(0,-1)) ? Number(args[args.length-1]) : addRecurse(...args.slice(0,-1)); 95 | } 96 | 97 | const maxRecurse = (...args) => { 98 | if (args.length === 1) 99 | return Number(args[0]); 100 | else 101 | return Number(args[args.length-1]) > addRecurse(...args.slice(0,-1)) ? Number(args[args.length-1]) : addRecurse(...args.slice(0,-1)); 102 | } 103 | 104 | 105 | const not = (func) => { 106 | func = false; 107 | return func; 108 | } -------------------------------------------------------------------------------- /Solutions/ayushi_solutions.js: -------------------------------------------------------------------------------- 1 | 2 | const identity = (x) => x; 3 | 4 | const addb = (a, b) => a + b; 5 | 6 | const subb = (a, b) => a - b; 7 | 8 | const mulb = (a, b) => a*b; 9 | 10 | const minb = (a, b) => a < b ? a : b; 11 | 12 | const maxb = (a, b) => a > b ? a : b; 13 | 14 | const add = (...nums) => nums.reduce((a, b)=>a+b) 15 | 16 | const sub = (...nums) => nums.reduce((a, b)=>a-b) 17 | 18 | const mul = (...nums) => nums.reduce((a, b)=>a*b , 1) 19 | 20 | const min = (...nums) => nums.reduce((a, b)=> Math.min(a, b)) 21 | 22 | const max = (...nums) => nums.reduce((a, b)=> Math.max(a, b)) 23 | 24 | const addRecurse = (...nums) => { 25 | if (nums.length === 1) return nums[0] 26 | return nums.pop() + addRecurse(...nums); 27 | } 28 | 29 | const mulRecurse = (...nums) => { 30 | if (nums.length === 1) return nums[0] 31 | return nums.pop() * mulRecurse(...nums); 32 | } 33 | 34 | const minRecurse = (...nums) => { 35 | if (nums.length === 1) return nums[0] 36 | let secondNum = minRecurse(...nums.slice(1)) 37 | if (nums[0] < secondNum) return nums[0] 38 | return secondNum 39 | } 40 | 41 | const maxRecurse = (...nums) => { 42 | if (nums.length === 1) return nums[0] 43 | let secondNum = maxRecurse(...nums.slice(1)) 44 | if (nums[0] > secondNum) return nums[0] 45 | return secondNum 46 | } 47 | 48 | const acc = (func, initial) => (...args) => { 49 | let x = initial; 50 | for (let i of args) { 51 | x = func(x, i); 52 | } 53 | return x; 54 | } 55 | 56 | const fill = (n) => { 57 | let arr = []; 58 | for(let i=0; i { 63 | if(arr.length === n){ 64 | return arr 65 | }else{ 66 | arr.push(n) 67 | return fillRecurse(n, arr) 68 | } 69 | } 70 | 71 | 72 | 73 | const pure = (x, y) => { 74 | const impure = (x) => { 75 | y++; 76 | z = x * y; 77 | } 78 | impure(x); 79 | return [y, z]; 80 | } 81 | 82 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, }; 83 | -------------------------------------------------------------------------------- /Solutions/brianwhelandublin.js: -------------------------------------------------------------------------------- 1 | const identity = (x) => x; 2 | 3 | const addb = (a, b) => a + b; 4 | 5 | const subb = (a, b) => a - b; 6 | 7 | const mulb = (a, b) => a * b; 8 | 9 | const minb = (a, b) => Math.min(a, b); 10 | 11 | const maxb = (a, b) => Math.max(a, b); 12 | 13 | const add = (...nums) => nums.reduce((acc, curr) => acc + curr); 14 | 15 | const sub = (...nums) => nums.reduce((acc, curr) => acc - curr); 16 | 17 | const mul = (...nums) => nums.reduce((acc, curr) => acc * curr); 18 | 19 | const min = (...nums) => Math.min(...nums); 20 | 21 | const max = (...nums) => Math.max(...nums); 22 | 23 | const addRecurse = (...nums) => { 24 | if (nums.length === 1) return nums[0]; 25 | return nums.pop() + addRecurse(...nums); 26 | }; 27 | 28 | const minRecurse = (...nums) => { 29 | const length = nums.length; 30 | if (length === 0) return; 31 | 32 | const min = (nums, len) => { 33 | if (len === 1) return nums[0]; 34 | return Math.min(nums[len - 1], min(nums, len - 1)); 35 | }; 36 | 37 | return min(nums, length); 38 | }; 39 | 40 | const maxRecurse = (...nums) => { 41 | const length = nums.length; 42 | if (length === 0) return; 43 | 44 | const max = (nums, len) => { 45 | if (len === 1) return nums[0]; 46 | return Math.max(nums[len - 1], max(nums, len - 1)); 47 | }; 48 | 49 | return max(nums, length); 50 | }; 51 | 52 | const not = 53 | (func) => 54 | (...args) => 55 | !func(...args); 56 | 57 | const acc = 58 | (func, initial) => 59 | (...args) => { 60 | let result = initial; 61 | for (let i of args) { 62 | final = finc(result, i); 63 | } 64 | return result; 65 | }; 66 | 67 | const fill = (num) => new Array(num).fill(num); 68 | 69 | const fillRecursive = (num, arr = []) => { 70 | if (arr.length === num) { 71 | return arr; 72 | } else { 73 | arr.push(num); 74 | return fillRecursive(num, arr); 75 | } 76 | }; 77 | 78 | const set = (...args) => { 79 | const result = []; 80 | for (let i = 0; i < args.length; i++) { 81 | if (!result.includes(args[i])) result.push(args[i]); 82 | } 83 | return result; 84 | }; 85 | 86 | const identityf = (x) => () => x; 87 | 88 | const addf = (a) => (b) => a + b; 89 | 90 | const litf = (func) => (a) => (b) => func(a, b); 91 | 92 | const inc = (x) => addb(x, 1); 93 | 94 | module.exports = { 95 | identity, 96 | addb, 97 | subb, 98 | mulb, 99 | minb, 100 | maxb, 101 | add, 102 | sub, 103 | mul, 104 | min, 105 | max, 106 | addRecurse, 107 | litf, 108 | minRecurse, 109 | maxRecurse, 110 | not, 111 | acc, 112 | fill, 113 | set, 114 | identityf, 115 | addf, 116 | }; 117 | -------------------------------------------------------------------------------- /Solutions/chirag_solutions.js: -------------------------------------------------------------------------------- 1 | const identity = x => x; 2 | 3 | const addb = (a,b) => a + b; 4 | 5 | const subb = (a,b) => a - b; 6 | 7 | const mulb = (a,b) => a * b; 8 | 9 | const minb = (a,b) => { 10 | if(a < b){ 11 | return a 12 | } 13 | 14 | return b; 15 | }; 16 | 17 | const maxb = (a,b) => { 18 | if(a > b){ 19 | return a 20 | } 21 | 22 | return b; 23 | }; 24 | 25 | const add = (...nums) => { 26 | let total = 0; 27 | for(let i in nums){ 28 | total = total + num[i] 29 | } 30 | 31 | return total; 32 | }; 33 | 34 | const sub = (...nums) => { 35 | let total = 0; 36 | for(let i in nums){ 37 | total = total - num[i] 38 | } 39 | 40 | return total; 41 | }; 42 | 43 | const mul = (...nums) => { 44 | let total = 0; 45 | for(let i in nums){ 46 | total = total * nums[i] 47 | } 48 | 49 | return total; 50 | }; 51 | 52 | const min = (...nums) => { 53 | let minNum = nums[0] 54 | for(let i in nums){ 55 | if(nums[i] < minNum){ 56 | minNum = nums[i]; 57 | } 58 | } 59 | 60 | return minNum; 61 | }; 62 | 63 | const max = (...nums) => { 64 | let maxNum = nums[0] 65 | for(let i in nums){ 66 | if(nums[i] > maxNum){ 67 | maxNum = nums[i]; 68 | } 69 | } 70 | 71 | return maxNum; 72 | }; 73 | 74 | const addRecurse = (...nums) => { 75 | if(nums.length === 1){ 76 | return nums[0]; 77 | } 78 | 79 | let [first, ...rest] = nums; 80 | 81 | return first + addRecurse(...rest); 82 | }; 83 | 84 | const mulRecurse = (...nums) => { 85 | if(nums.length === 1){ 86 | return nums[0]; 87 | } 88 | 89 | let [first, ...rest] = nums; 90 | 91 | return first * mulRecurse(...rest); 92 | }; 93 | 94 | const not = ( func ) => { 95 | return !func(); 96 | }; 97 | 98 | const acc = (func, initial) => { 99 | return function(...args){ 100 | return func(initial, ...args); 101 | } 102 | }; 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, }; -------------------------------------------------------------------------------- /Solutions/cyborg7459.js: -------------------------------------------------------------------------------- 1 | const identity = (x) => { 2 | return x; 3 | } 4 | 5 | const addb = (a,b) => { 6 | return a+b; 7 | } 8 | 9 | const subb = (a,b) => { 10 | return a-b; 11 | } 12 | 13 | const mulb = (a,b) => { 14 | return a*b; 15 | } 16 | 17 | const minb = (a,b) => { 18 | if(a>b) return b; 19 | else return a; 20 | } 21 | 22 | const maxb = (a,b) => { 23 | if(a>b) return a; 24 | else return b; 25 | } 26 | 27 | const add = (...arguments) => { 28 | let sum=0; 29 | for(let i=0; i { 36 | let diff = arguments[0]; 37 | for(let i=1; i { 44 | let prod=1; 45 | for(let i=0; i { 52 | let min=arguments[0]; 53 | for(let i=0; i { 61 | let max=arguments[0]; 62 | for(let i=0; imax) 64 | max = arguments[i]; 65 | } 66 | return max; 67 | } 68 | 69 | const addRecurse = (...args) => { 70 | if(args.length === 1) 71 | return Number(args[0]); 72 | else 73 | return Number(args[args.length-1]) + addRecurse(...args.slice(0,-1)); 74 | } 75 | 76 | const mulRecurse = (...args) => { 77 | if(args.length === 1) 78 | return Number(args[0]); 79 | else 80 | return Number(args[args.length-1]) * mulRecurse(...args.slice(0,-1)); 81 | } 82 | 83 | const maxRecurse = (...args) => { 84 | if(args.length === 1) 85 | return Number(args[0]); 86 | else 87 | return Number(args[args.length-1]) > (maxRecurse(...args.slice(0,-1))) ? Number(args[args.length-1]) : (maxRecurse(...args.slice(0,-1))) ; 88 | } 89 | 90 | const minRecurse = (...args) => { 91 | if(args.length === 1) 92 | return Number(args[0]); 93 | else 94 | return Number(args[args.length-1]) < (minRecurse(...args.slice(0,-1))) ? Number(args[args.length-1]) : (minRecurse(...args.slice(0,-1))) ; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /Solutions/d3kelleyy.js: -------------------------------------------------------------------------------- 1 | // Take and return argument 2 | const identity = (arg) => arg; 3 | 4 | identity('Hello World!'); //Returns Hello World! 5 | 6 | //Takes two numbers and returns sum 7 | 8 | const addb = (num1, num2) => num1 + num2; 9 | 10 | addb(5, 9); //Returns 14 11 | 12 | //Takes two numbers and returns difference 13 | const subb = (num1, num2) => num1 - num2; 14 | 15 | subb(20, 7); //Returns 13 16 | 17 | //Takes two numbers and returns product 18 | const mulb = (num1, num2) => num1 * num2; 19 | 20 | mulb(10, 12); //Returns 120 21 | 22 | //Takes two numbers and returns the smaller one 23 | const minb = (num1, num2) => Math.min(num1, num2); 24 | 25 | minb(70, 30); //Returns 30 26 | 27 | //Takes two numbers and returns the larger one 28 | const maxb = (num1, num2) => Math.max(num1, num2); 29 | 30 | maxb(70, 30); //Returns 70 31 | 32 | //Write a function add that is generalized for any amount of arguments and adds them 33 | const add = (...nums) => { 34 | return nums.reduce((acc, cur) => { 35 | return acc + cur; 36 | }); 37 | }; 38 | 39 | add(3, 5, 7, 20); //Returns 35 40 | 41 | //Write a function sub that is generalized for any amount of arguments and subtracts them 42 | const sub = (...nums) => { 43 | return nums.reduce((acc, cur) => { 44 | return acc - cur; 45 | }); 46 | }; 47 | sub(5, 8, 11, 3); //Returns -17 48 | 49 | //Write a function mul that is generalized for any amount of arguments and multiplies them 50 | const mul = (...nums) => { 51 | return nums.reduce((acc, cur) => { 52 | return acc * cur; 53 | }); 54 | }; 55 | 56 | mul(9, 5, 3); //Returns 135; 57 | 58 | //Write a function min that is generalized for any amount of arguments and returns the lowest 59 | const min = (...nums) => { 60 | return nums.reduce((acc, cur) => { 61 | return Math.min(acc, cur); 62 | }); 63 | }; 64 | 65 | min(20, 9, 12); //Returns 9 66 | 67 | //Write a function min that is generalized for any amount of arguments and returns the highest 68 | const max = (...nums) => { 69 | return nums.reduce((acc, cur) => { 70 | return Math.max(acc, cur); 71 | }); 72 | }; 73 | 74 | max(20, 9, 12); //Returns 20 75 | 76 | const addRecurse = (numArray) => { 77 | if (numArray.length === 1) { 78 | return numArray[0]; 79 | } else { 80 | return numArray.pop() + addRecurse(numArray); 81 | } 82 | }; 83 | 84 | console.log(addRecurse([4, 5])); 85 | -------------------------------------------------------------------------------- /Solutions/danmachlenkin.js: -------------------------------------------------------------------------------- 1 | const identity = (argument) => argument ; 2 | ///////////////////////////////////////// 3 | const addb = (a,b) => a + b ; 4 | ///////////////////////////////////////// 5 | const subb = (a,b) => a-b; 6 | ///////////////////////////////////////// 7 | const mulb = (a,b) => a*b; 8 | ///////////////////////////////////////// 9 | const minb = (a,b) => a < b ? a : b ; 10 | ///////////////////////////////////////// 11 | const maxb = (a,b) => a > b ? a : b ; 12 | ///////////////////////////////////////// 13 | const add = (...nums) => { 14 | return nums.reduce((acc,current) =>{ 15 | return acc+current; 16 | }) 17 | }; 18 | ///////////////////////////////////////// 19 | const sub = (...nums) => { 20 | return nums.reduce((acc,current) => { 21 | return acc - current; 22 | },0) 23 | }; 24 | ///////////////////////////////////////// 25 | const mul = (...nums) => { 26 | return nums.reduce((acc,current) => { 27 | return acc * current; 28 | },1) 29 | }; 30 | ///////////////////////////////////////// -------------------------------------------------------------------------------- /Solutions/danteSadeghiSolutions.js: -------------------------------------------------------------------------------- 1 | // function minb(a, b) { 2 | // let min; 3 | // return min = (a < b) ? a : b; 4 | // } 5 | 6 | const minb = (a, b) => (a < b) ? a : b; 7 | 8 | function add(...nums) { 9 | let sum = 0; 10 | for (let num of nums) { 11 | sum += num; 12 | } 13 | return sum; 14 | } 15 | 16 | function mul(...nums) { 17 | let product = 1; 18 | for (let num of nums) { 19 | product *= num; 20 | } 21 | return product; 22 | } 23 | 24 | function mulRecurse(...nums) { 25 | if (nums.length == 1) { 26 | return nums[0]; 27 | } 28 | currNum = nums[0]; 29 | nums.shift(); // E.g. [1, 2, 3] --> [2, 3] 30 | // 1 * mulRecurse([2, 3]) 31 | // 1 * (2 * mulRecurse([3])) 32 | // 1 * (2 * (3)) 33 | return currNum * mulRecurse(...nums); 34 | } 35 | 36 | module.exports = { 37 | // identity, 38 | // addb, 39 | // subb, 40 | // mulb, 41 | minb, 42 | // maxb, 43 | add, 44 | // sub, 45 | mul, 46 | // min, 47 | // max, 48 | // addRecurse, 49 | mulRecurse, 50 | // minRecurse, 51 | // maxRecurse, 52 | // not, 53 | // acc, 54 | // accPartial, 55 | // accRecurse, 56 | // fill, 57 | // fillRecurse, 58 | // set, 59 | // identityf, 60 | // addf, 61 | // liftf, 62 | // pure, 63 | // curryb, 64 | // curry, 65 | // inc, 66 | // twiceUnary, 67 | // doubl, 68 | // square, 69 | // twice, 70 | // reverseb, 71 | // reverse, 72 | // composeuTwo, 73 | // composeu, 74 | // composeb, 75 | // composeTwo, 76 | // compose, 77 | // limitb, 78 | // limit, 79 | // genFrom, 80 | // genTo, 81 | // genFromTo, 82 | // elementGen, 83 | // element, 84 | // collect, 85 | // filter, 86 | // filterTail, 87 | // concatTwo, 88 | // concat, 89 | // concatTail, 90 | // gensymf, 91 | // gensymff, 92 | // fibonaccif, 93 | // counter, 94 | // revocableb, 95 | // revocable, 96 | // extract, 97 | // m, 98 | // addmTwo, 99 | // addm, 100 | // liftmbM, 101 | // liftmb, 102 | // liftm, 103 | // exp, 104 | // expn, 105 | // addg, 106 | // liftg, 107 | // arrayg, 108 | // continuizeu, 109 | // continuize, 110 | // vector, 111 | // exploitVector, 112 | // vectorSafe, 113 | // pubsub, 114 | // mapRecurse, 115 | // filterRecurse, 116 | }; -------------------------------------------------------------------------------- /Solutions/david_001_solutions copy.js: -------------------------------------------------------------------------------- 1 | function identity(x){ 2 | return x; 3 | } 4 | 5 | function addb(a,b){ 6 | return a+b; 7 | } 8 | 9 | function subb(a,b){ 10 | return a-b; 11 | } 12 | 13 | function mulb(a,b){ 14 | return a*b; 15 | } 16 | 17 | function minb(a, b){ 18 | return ab ? a : b; 23 | } 24 | 25 | function add(...nums){ 26 | let sum=0; 27 | for(let i=0; ians ? nums[i] : ans; 61 | } 62 | return ans; 63 | } 64 | 65 | function addRecurse(...nums){ 66 | if(nums.length==1){ 67 | return nums[0]; 68 | } 69 | return nums.pop() + addRecurse(...nums); 70 | } 71 | 72 | function mulRecurse(...nums){ 73 | if(nums.length==1){ 74 | return nums[0]; 75 | } 76 | return nums.pop() * mulRecurse(...nums); 77 | } 78 | 79 | module.exports = {identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse}; -------------------------------------------------------------------------------- /Solutions/david_001_solutions.js: -------------------------------------------------------------------------------- 1 | function identity(x){ 2 | return x; 3 | } 4 | 5 | function addb(a,b){ 6 | return a+b; 7 | } 8 | 9 | function subb(a,b){ 10 | return a-b; 11 | } 12 | 13 | function mulb(a,b){ 14 | return a*b; 15 | } 16 | 17 | function minb(a, b){ 18 | return ab ? a : b; 23 | } 24 | 25 | function add(...nums){ 26 | let sum=0; 27 | for(let i=0; ians ? nums[i] : ans; 61 | } 62 | return ans; 63 | } 64 | 65 | function addRecurse(...nums){ 66 | if(nums.length==1){ 67 | return nums[0]; 68 | } 69 | return nums.pop() + addRecurse(...nums); 70 | } 71 | 72 | function mulRecurse(...nums){ 73 | if(nums.length==1){ 74 | return nums[0]; 75 | } 76 | return nums.pop() * mulRecurse(...nums); 77 | } 78 | 79 | module.exports = {identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse}; -------------------------------------------------------------------------------- /Solutions/ezClops_Solution.js: -------------------------------------------------------------------------------- 1 | const { identity } = require("lodash"); 2 | 3 | /*Write a function identity that takes an argument and returns that argument*/ 4 | function identity(x){ 5 | return x; 6 | } 7 | /*Write a binary function addb that takes two numbers and returns their sum*/ 8 | function addb(a, b) { 9 | return a + b; 10 | } 11 | /*Write a binary function subb that takes two numbers and returns their difference*/ 12 | function subb(a, b) { 13 | return b - a; 14 | } 15 | /*Write a binary function mulb that takes two numbers and returns their product*/ 16 | function mulb(a, b) { 17 | return a * b; 18 | } 19 | /*Write a binary function minb that takes two numbers and returns 20 | the smaller one*/ 21 | function minb(a, b) { 22 | if (a < b) return a; 23 | return b; 24 | } 25 | /*Write a binary function maxb that takes two numbers and returns the larger one*/ 26 | function maxb(a, b) { 27 | if (a > b) return a; 28 | return b; 29 | } 30 | /*Write a function add that is generalized for any amount of arguments*/ 31 | function add(...num) { 32 | let array = [...num]; 33 | let array2 = array[0]; 34 | let sum = 0; 35 | array2.forEach(n => sum += n); 36 | return sum; 37 | } 38 | /*Write a function sub that is generalized for any amount of arguments*/ 39 | function sub(...num) { 40 | let array = [...num]; 41 | let array2 = array[0]; 42 | let subt = 0; 43 | array2.forEach((n, i) => { 44 | if(i === 0){subt = n;} 45 | else{subt -= n;} 46 | }); 47 | return subt; 48 | } 49 | /*Write a function mul that is generalized for any amount of arguments*/ 50 | function mul(...num) { 51 | let array = [...num]; 52 | let array2 = array[0]; 53 | let mult = 1; 54 | array2.forEach(n => mult *= n); 55 | return mult; 56 | } 57 | /*Write a function min that is generalized for any amount of arguments*/ 58 | function min(...num) { 59 | let array = [...num]; 60 | let array2 = array[0]; 61 | let mini = 0; 62 | array2.forEach((n, i) => { 63 | if (i === 0){mini = n;} 64 | for (j = i + 1; j < array2.length; j++) { 65 | if (array2[j] < mini){mini = array2[j]} 66 | } 67 | }); 68 | return mini; 69 | } 70 | /*Write a function max that is generalized for any amount of arguments*/ 71 | function max(...num) { 72 | let array = [...num]; 73 | let array2 = array[0]; 74 | let maxi = 0; 75 | array2.forEach((n, i) => { 76 | if (i === 0){maxi = n;} 77 | for (j = i + 1; j < array2.length; j++) { 78 | if (array2[j] > maxi){maxi = array2[j]} 79 | } 80 | }); 81 | return maxi; 82 | } 83 | /*Write a function addRecurse that is the generalized add function but uses recursion*/ 84 | function addRecurse(...num) { 85 | const array = [...num]; 86 | let sum = 0; 87 | const array2 = [...array[0]]; 88 | if (array2.length > 0) { 89 | let n = array2.shift(); 90 | sum = n + addRecurse(array2); 91 | } 92 | return sum; 93 | } 94 | /*Write a function mulRecurse that is the generalized mul function but uses recursion*/ 95 | function mulRecurse(...num) { 96 | const array = [...num]; 97 | const array2 = [...array[0]]; 98 | let prod = 1; 99 | if (array2.length > 0) { 100 | let n = array2.shift(); 101 | prod = n * mulRecurse(array2); 102 | } 103 | return prod; 104 | } 105 | /*Write a function minRecurse that is the generalized min function but uses recursion*/ 106 | function minRecurse(...num) { 107 | const array = num[0]; 108 | const array2 = [...array]; 109 | let min = array2[0]; 110 | 111 | if (array2.length === 1) {return min} 112 | array2.shift(); 113 | let newMin = minRecurse(array2); 114 | if (min > newMin) {min = newMin} 115 | 116 | return min; 117 | } 118 | /*Write a function maxRecurse that is the generalized max function but uses recursion*/ 119 | function maxRecurse(...num) { 120 | const array = num[0]; 121 | const array2 = [...array]; 122 | let max = array2[0]; 123 | 124 | if (array2.length === 1) {return max} 125 | array2.shift(); 126 | let newMax = maxRecurse(array2); 127 | if (max < newMax) {max = newMax} 128 | 129 | return max; 130 | } 131 | //Write a function not that takes a function and returns the negation of its result 132 | function not(func) { 133 | if (func === true) { 134 | return false; 135 | }else{return true} 136 | } 137 | /*Write a function acc that takes a function and an initial value and returns a function that runs the initial function on each argument, accumulating the result*/ 138 | function acc(func, initial) { 139 | 140 | } 141 | module.exports = { 142 | identity, 143 | addb, 144 | subb, 145 | mulb, 146 | minb, 147 | add, 148 | sub, 149 | mul, 150 | min, 151 | max, 152 | addRecurse, 153 | mulRecurse, 154 | minRecurse, 155 | maxRecurse, 156 | not 157 | }; -------------------------------------------------------------------------------- /Solutions/filterRecurse_solution.js: -------------------------------------------------------------------------------- 1 | /* 2 | filterRecurse([ 1, 2, 3, 4 ], x => x % 2 === 0) // [ 2, 4 ] 3 | */ 4 | 5 | let filterRecurse = (arr,func) =>{ 6 | if (arr.length){ 7 | 8 | if (func(arr[0])){ 9 | return [arr[0]].concat(filterRecurse(arr.slice(1,arr.length),func)) 10 | } 11 | else{ 12 | return filterRecurse(arr.slice(1,arr.length),func) 13 | } 14 | 15 | } 16 | else{ 17 | return [] 18 | } 19 | 20 | } 21 | 22 | console.log(filterRecurse([ 1, 2, 3, 4 ], x => x % 2 === 0)) 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Solutions/fun-soulution.js: -------------------------------------------------------------------------------- 1 | //1.Write a function identity that takes an argument and returns that argument 2 | const identity = (x) => { return x }; 3 | identity(5); //returns 5 4 | 5 | //2.Write a binary function addb that takes two numbers and returns their sum 6 | const addb = (x,y) =>{ return x + y }; 7 | addb(5,6); //return 11 8 | //3.Write a binary function subb that takes two numbers and returns their difference 9 | const subb = (x,y) =>{ return x - y }; 10 | subb(11,3) //return 8 11 | 12 | //3.Write a binary function mulb that takes two numbers and returns their product 13 | const mulb = (x,y) =>{ return x * y }; 14 | 15 | //4.Write a binary function minb that takes two numbers and returns the smaller one 16 | const minb = (x,y) =>{ 17 | if (x>y) { 18 | return y; 19 | }else{ 20 | return x; 21 | } 22 | }; 23 | 24 | //5.Write a binary function maxb that takes two numbers and returns the larger one 25 | const maxb = (x,y) =>{ 26 | if (x > y) { 27 | return x; 28 | }else{ 29 | return y; 30 | } 31 | }; 32 | //7.Write a function add that is generalized for any amount of arguments 33 | const add = (...nums) =>{ 34 | return nums.reduce((a,b)=> a+b); 35 | } 36 | add(2,4,2,1,4) //return 13 37 | 38 | //8.Write a function sub that is generalized for any amount of arguments 39 | const sub = (...nums) =>{ 40 | return nums.reduce((a,b)=> a-b); 41 | } 42 | sub(234,41,2,1,4) //return 186 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Solutions/fun.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | 3 | // const identity = function identity(x) { 4 | // return x 5 | // } 6 | //OR 7 | const identity = (x) => x; 8 | console.log(identity('Hello Slavo')); 9 | console.log('---------------------'); 10 | 11 | // Write a binary function addb that takes two numbers and returns their sum 12 | 13 | const addb = (a, b) => { 14 | return a + b 15 | } 16 | console.log(addb(3, 4)) 17 | console.log('-----------------------') 18 | 19 | // Write a binary function subb that takes two numbers and returns their 20 | // difference 21 | 22 | const subb = (a, b) => { 23 | return a - b 24 | } 25 | console.log(subb(3, 4)); 26 | console.log('----------------------') 27 | 28 | // Write a binary function mulb that takes two numbers and returns their product 29 | 30 | const mulb = (a, b) => { 31 | return a * b 32 | } 33 | console.log(mulb(3, 4)) 34 | console.log('-------------------') 35 | 36 | // Write a binary function minb that takes two numbers and returns the smaller 37 | // one 38 | 39 | const minb = (a, b) => { 40 | return a < b 41 | ? a 42 | : b 43 | } 44 | console.log(minb(3, 4)) 45 | console.log('--------------------') 46 | 47 | // Write a binary function maxb that takes two numbers and returns the larger 48 | // one 49 | 50 | const maxb = (a, b) => { 51 | return a > b 52 | ? a 53 | : b 54 | } 55 | console.log(maxb(3, 4)); 56 | console.log('---------------------------') 57 | 58 | // Write a function add that is generalized for any amount of arguments 59 | 60 | const add = (...nums) => { 61 | return nums.reduce((a, b) => a + b) 62 | } 63 | console.log("add " + add(1, 2, 4, 5)) 64 | console.log('-----------------'); 65 | 66 | // Write a function sub that is generalized for any amount of arguments 67 | 68 | const sub = (...nums) => { 69 | return nums.reduce((a, b) => a - b) 70 | } 71 | 72 | console.log(sub(1, 2, 4)) 73 | console.log('-----------------'); 74 | 75 | // Write a function mul that is generalized for any amount of arguments 76 | 77 | const mul = (...nums) => { 78 | return nums.reduce((a, b) => a * b) 79 | } 80 | 81 | console.log(mul(1, 2, 4)) 82 | console.log('-----------------'); 83 | 84 | // Write a function min that is generalized for any amount of arguments 85 | 86 | const min = (...nums) => { 87 | return nums.reduce((a, b) => a < b 88 | ? a 89 | : b); 90 | } 91 | 92 | console.log(min(7, 2, 1, 35, -1, -9, 44, 67)) 93 | console.log('-----------------'); 94 | 95 | // Write a function max that is generalized for any amount of arguments 96 | 97 | const max = (...nums) => { 98 | return nums.reduce((a, b) => a > b 99 | ? a 100 | : b) 101 | } 102 | 103 | console.log(max(7, 2, 1, 35, 567, -1, -9, 44, 67)) 104 | console.log('-----------------'); 105 | 106 | // Write a function addRecurse that is the generalized add function but uses 107 | // recursion 108 | 109 | function addRecurse(...nums) { 110 | if (nums.length < 1) { 111 | return 0; 112 | } 113 | if (nums.length === 1) { 114 | return nums[0]; 115 | } 116 | return nums[0] + addRecurse(...nums.slice(1)); 117 | } 118 | 119 | console.log(addRecurse(1, 2, 4)) 120 | console.log('-----------------'); 121 | 122 | // Write a function mulRecurse that is the generalized mul function but uses 123 | // recursion 124 | 125 | const mulRecurse = (...nums) => { 126 | if (nums.length < 1) { 127 | return 0 128 | } 129 | 130 | if (nums.length == 1) { 131 | return nums[0] 132 | } 133 | 134 | return nums[0] * mulRecurse(...nums.slice(1)) 135 | } 136 | 137 | console.log(mulRecurse(1, 2, 4)) 138 | console.log('-----------------'); 139 | 140 | // Write a function minRecurse that is the generalized min function but uses 141 | // recursion 142 | 143 | const minRecurseMy = (...nums) => { 144 | if (nums.length < 1) { 145 | return 'Empty Array' 146 | } 147 | 148 | if (nums.length === 1) { 149 | return nums[0] 150 | } 151 | 152 | return nums[0] < minRecurseMy(...nums.slice(1)) 153 | ? nums[0] 154 | : minRecurseMy(...nums.slice(1)) 155 | } 156 | 157 | console.log(minRecurseMy(1, 2, 6, 7, -6, 9, 44, 4)) 158 | console.log('-----------------'); 159 | 160 | function minRecurse(...nums) { 161 | if (nums.length < 1) { 162 | return Number.MAX_VALUE; 163 | } 164 | if (nums.length === 1) { 165 | return nums[0]; 166 | } 167 | return minb(nums[0], minRecurse(...nums.slice(1))); 168 | } 169 | 170 | console.log(minRecurse(2, 6, 7, -6, 9, 44, 4)) 171 | console.log('-----------------'); 172 | 173 | // Write a function maxRecurse that is the generalized max function but uses 174 | // recursion 175 | 176 | const maxRecurse = (...nums) => { 177 | if (nums.length < 1) { 178 | return 'Empty Array' 179 | } 180 | 181 | if (nums.length === 1) { 182 | return nums[0] 183 | } 184 | 185 | return maxb(nums[0], maxRecurse(...nums.slice(1))) 186 | } 187 | 188 | console.log(maxRecurse(2, 6, 7, -6, 9, 44, 4)) 189 | console.log('-----------------'); 190 | 191 | // Write a function not that takes a function and returns the negation of its 192 | // result 193 | 194 | const not = (a) => { 195 | return function (...args) { 196 | return !a(...args); 197 | }; 198 | } 199 | const isOdd = x => x % 2 === 1; 200 | const isEven = not(isOdd); 201 | 202 | console.log(isEven(3)) 203 | console.log('-----------------'); 204 | 205 | // Write a function acc that takes a function and an initial value and returns a 206 | // function that runs the initial function on each argument, accumulating the 207 | // result 208 | 209 | function acc(func, initial) { 210 | return function (...args) { 211 | return args.reduce((result, curr, idx) => { 212 | return func(result, curr, idx) 213 | }, initial); 214 | }; 215 | } 216 | let add_d = acc(addb, 4) 217 | let mul_b = acc(mulb, 2) 218 | console.log(add_d(1, 2, 3)) 219 | console.log(mul_b(2, 3, 3)) 220 | console.log('-----------------') 221 | 222 | // Write a function accPartial that takes in a function, a start index, and an 223 | // end index, and returns a function that accumulates a subset of its arguments 224 | // by applying the given function to all elements between start and end. 225 | 226 | const addSecondToThird = accPartial(add, 1, 3); 227 | addSecondToThird(1, 2, 4, 8) // [ 1, 6, 8 ] 228 | 229 | // Write a function addf that adds from two invocations. 230 | 231 | const addf = a => b => a + b 232 | 233 | console.log(addf(3)(4)); 234 | console.log('-----------------'); 235 | 236 | // Write a function to find sum of all elements of an array; 237 | const arraySum=[5,10,8,7,11,13]; 238 | const sum=arraySum.reduce((acc,item)=>acc+item,0); 239 | console.log(sum); 240 | 241 | // Use the code to create the square function 242 | const square = (x) => { 243 | 244 | // Use the code to create the square function 245 | const square = (x) => { 246 | console.log(x**2); 247 | } 248 | square(); 249 | //OR 250 | const square = (x) => x**2; 251 | square() 252 | 253 | // Use the code to create the cube function 254 | const cube = (y) => { 255 | console.log(y**3); 256 | } 257 | cube(); 258 | //OR 259 | const cube= (y) => y**3; 260 | cube() 261 | 262 | 263 | 264 | 265 | 266 | -------------------------------------------------------------------------------- /Solutions/funExercises.js: -------------------------------------------------------------------------------- 1 | //write a function 'identity' that takes in an argument and returns that argument 2 | arg = prompt('input anything'); 3 | const identity = (arg) => arg; 4 | console.log(identity(arg)) 5 | console.log('------------------') 6 | 7 | 8 | //write a function 'addb' that takes two numbers and returns their sum 9 | let a = prompt('input first number'); 10 | let b = prompt('input second number'); 11 | const addb = (a,b) => { 12 | const c = Number(a) + Number(b); 13 | return c 14 | } 15 | console.log(addb(a, b)) 16 | console.log('------------------') 17 | 18 | 19 | //write a function 'subb' that takes two numbers and returns their difference 20 | let a = prompt('input first number'); 21 | let b = prompt('input second number'); 22 | const subb = (a, b) => { 23 | const c = Number(a) - Number(b); 24 | return c 25 | } 26 | console.log(subb(a, b)) 27 | console.log('------------------') 28 | 29 | 30 | //write a function 'mulb' that takes two numbers and returns their product 31 | let a = prompt('input first number'); 32 | let b = prompt('input second number'); 33 | const mulb = (a, b) => { 34 | const c = Number(a) * Number(b); 35 | return c 36 | } 37 | console.log(mulb(a, b)) 38 | console.log('------------------') 39 | 40 | 41 | //write a function 'minb' that takes two numbers and returns the smaller one 42 | let a = prompt('input first number'); 43 | let b = prompt('input second number'); 44 | const minb = (a, b) => { 45 | if (Number(a) < Number(b)) { 46 | return a 47 | } else { 48 | return b 49 | } 50 | } 51 | console.log(minb(a, b)) 52 | console.log('------------------') 53 | 54 | 55 | //write a function 'maxb' that takes two numbers and returns the larger one 56 | let a = prompt('input first number'); 57 | let b = prompt('input second number'); 58 | const maxb = (a, b) => { 59 | if (Number(a) > Number(b)) { 60 | return a 61 | } else { 62 | return b 63 | } 64 | } 65 | console.log(maxb(a, b)) 66 | console.log('------------------') 67 | 68 | 69 | //write a function 'add' that is generalized for any amount of arguments 70 | const add = (...nums) => { 71 | return nums.reduce((a, b) => 72 | a + b) 73 | } 74 | console.log(add(2, 3, 4, 5)) 75 | console.log('------------------') 76 | 77 | 78 | //write a function 'sub' that is generalized for any amount of arguments 79 | const sub = (...nums) => { 80 | return nums.reduce((a, b) => 81 | a - b) 82 | } 83 | console.log(sub(2, 3, 4, 5)) 84 | console.log('------------------') 85 | 86 | 87 | //write a function 'mul' that is generalized for any amount of arguments 88 | const mul = (...nums) => { 89 | return nums.reduce((a, b) => 90 | a * b) 91 | } 92 | console.log(mul(2, 3, 4, 5)) 93 | console.log('------------------') 94 | 95 | 96 | //write a function 'min' that is generalized for any amount of arguments 97 | const min = (...nums) => { 98 | return nums.reduce((a, b) => { 99 | if (a < b) { 100 | return a 101 | } else { 102 | return b 103 | } 104 | }) 105 | } 106 | console.log(min(2, 3, 4, 5)) 107 | console.log('------------------') 108 | 109 | 110 | 111 | //write a function 'max' that is generalized for any amount of arguments 112 | const max = (...nums) => { 113 | return nums.reduce((a, b) => { 114 | if (a > b) { 115 | return a 116 | } else { 117 | return b 118 | } 119 | }) 120 | } 121 | console.log(max(2, 3, 4, 5)) 122 | console.log('------------------') 123 | 124 | 125 | const addRecurse = (...nums) => { 126 | return nums[0] + addRecurse(nums.slice(1)) 127 | }// stack overflow 128 | 129 | 130 | //write a function that takes a function and returns the negation of it's result 131 | const isOdd = (num) => { 132 | return (num%2!=0?true:false); 133 | } 134 | const not = (func) => { 135 | return !func; 136 | } 137 | console.log(not(isOdd(2))) 138 | console.log('--------------') 139 | 140 | 141 | const acc = (func, initial) => { 142 | return insider = () =>{ 143 | return insider.reduce((a, 5) =>{ 144 | a * 5 145 | }, initial) 146 | } 147 | } 148 | 149 | console.log(acc(5, 1, 2)) 150 | console.log('---------------') 151 | 152 | 153 | //write a function 'set' that is given a list of arguments and returns an array with all duplicates removed 154 | const set = (args) => { 155 | let x = []; 156 | args.forEach(function(i) { 157 | if (!x[i]) {x[i] = true} 158 | }); 159 | return Object.keys(x) 160 | } 161 | 162 | set([1, 2, 2, 3, 5, 4, 6, 4, 9]) 163 | console.log('----------------') 164 | -------------------------------------------------------------------------------- /Solutions/fun_Js_Bhavesh.js: -------------------------------------------------------------------------------- 1 | const identity = (a) => { 2 | return a; 3 | } 4 | 5 | const addb = (a,b) => { 6 | return a + b; 7 | } 8 | 9 | const subb = (a,b) => { 10 | return a - b; 11 | } 12 | 13 | const mulb = (a,b) => { 14 | return a * b; 15 | } 16 | 17 | const minb = (a,b) => { 18 | if (a < b){ 19 | return a 20 | } else { 21 | return b 22 | } 23 | } 24 | 25 | const maxb = (a,b) => { 26 | if (a < b){ 27 | return b 28 | } else { 29 | return a 30 | } 31 | } 32 | 33 | const add = (...nums) => { 34 | let total = 0; 35 | 36 | for(let i=0; i { 44 | let total = 0 45 | 46 | for (let i=0; i< nums.length; i++){ 47 | total -= nums[i] 48 | } 49 | 50 | return total 51 | } 52 | 53 | const mul = (...nums) => { 54 | let total = 0; 55 | 56 | for (let i=0; i < nums.length; i++){ 57 | total *= nums[i] 58 | } 59 | 60 | return total 61 | } 62 | 63 | const min = (...nums) => { 64 | const sorted = nums.sort((a,b)=> a - b) 65 | 66 | return sorted[0] 67 | } 68 | 69 | const max = (...nums) => { 70 | const sorted = nums.sort((a,b)=> b - a) 71 | 72 | return sorted[0] 73 | } 74 | 75 | const addRecurse = (...nums) => { 76 | if (nums.length <= 0){ 77 | return 0 78 | } 79 | 80 | return nums[0] + addRecurse(...nums.slice(1)) 81 | } 82 | 83 | const mulRecurse = (...nums) => { 84 | if (nums.length <= 0){ 85 | return 1 86 | } 87 | 88 | return nums[0] * mulRecurse(...nums.slice(1)) 89 | } 90 | 91 | 92 | module.exports = { 93 | identity, 94 | addb, 95 | subb, 96 | mulb, 97 | minb, 98 | maxb, 99 | add, 100 | sub, 101 | mul, 102 | min, 103 | max, 104 | } -------------------------------------------------------------------------------- /Solutions/fun_solution.js: -------------------------------------------------------------------------------- 1 | // add my solution file 2 | 3 | // 1. identity 4 | const identity = x => x; 5 | console.log(identity(3)); 6 | 7 | // 2. add 8 | const addb = (a, b) => a + b; 9 | console.log(addb(3, 4)); 10 | 11 | // 3. subb 12 | const subb = (a, b) => a - b; 13 | console.log(subb(3, 4)); 14 | 15 | // 4. mulb 16 | const mulb = (a, b) => a * b; 17 | console.log(mulb(3, 4)); 18 | 19 | // 5. minb 20 | const minb = (a, b) => a < b ? a : b; 21 | console.log(minb(3, 4)); 22 | 23 | // 6. maxb 24 | const maxb = (a, b) => a > b ? a : b; 25 | console.log(maxb(3, 4)); 26 | 27 | // 7. add 28 | const add = (...nums) => nums.reduce((acc, num) => acc + num, 0); 29 | console.log(add(1, 2, 3, 4)); 30 | 31 | // 8. sub 32 | const sub = (...nums) => { 33 | let result = nums[0]; 34 | for (let index = 1; index < nums.length; index++) { 35 | result -= nums[index]; 36 | } 37 | return result; 38 | } 39 | console.log(sub(1, 2, 3, 4)); 40 | 41 | // 9. mul 42 | const mul = (...nums) => nums.reduce((acc, num) => acc * num, 1); 43 | console.log(mul(1, 2, 3, 4)); 44 | 45 | // 10. min 46 | const min = (...nums) => { 47 | let minNumber = nums[0]; 48 | for (let index = 1; index < nums.length; index++) { 49 | if (nums[index] < minNumber) { 50 | minNumber = nums[index]; 51 | } 52 | } 53 | return minNumber; 54 | } 55 | console.log(min(1, 2, 3, 4)); 56 | 57 | // 11. max 58 | const max = (...nums) => { 59 | let maxNumber = nums[0]; 60 | for (let index = 1; index < nums.length; index++) { 61 | if (nums[index] > maxNumber) { 62 | maxNumber = nums[index]; 63 | } 64 | } 65 | return maxNumber; 66 | } 67 | console.log(max(1, 2, 3, 4)); 68 | 69 | // 12. addRecurse 70 | const addRecurse = (...nums) => { 71 | if (nums.length == 1) return nums[0]; 72 | let currAdd = nums[0]; 73 | nums.shift(); 74 | return currAdd + addRecurse(...nums); 75 | } 76 | console.log(addRecurse(1, 2, 3, 4)); 77 | 78 | // 13. mulRecurse 79 | const mulRecurse = (...nums) => { 80 | if (nums.length == 1) return nums[0]; 81 | let currMul = nums[0]; 82 | nums.shift(); 83 | return currMul * mulRecurse(...nums); 84 | } 85 | console.log(mulRecurse(1, 2, 3, 4)); 86 | 87 | // 14. minRecurse 88 | const minRecurse = (...nums) => { 89 | if (nums.length == 1) return nums[0]; 90 | let currMin = nums[0]; 91 | nums.shift(); 92 | return minb(currMin, minRecurse(...nums)); 93 | } 94 | console.log(minRecurse(1, 2, 3, 4)); 95 | 96 | // 15. maxRecurse 97 | const maxRecurse = (...nums) => { 98 | if (nums.length == 1) return nums[0]; 99 | let currMax = nums[0]; 100 | nums.shift(); 101 | return maxb(currMax, minRecurse(...nums)); 102 | } 103 | console.log(maxRecurse(1, 2, 3, 4)); 104 | 105 | // 16. not 106 | const not = func => { 107 | return (arg) => { 108 | if (func(arg)) { 109 | return false; 110 | } 111 | return true; 112 | } 113 | } 114 | const isOdd = x => x % 2 === 1; 115 | const isEven = not(isOdd); 116 | console.log(isEven(1)); // false 117 | console.log(isEven(2)); // true 118 | 119 | // 17. acc 120 | const acc = (func, initial) => { 121 | return (...nums) => { 122 | let init = initial; 123 | for (const num of nums) { 124 | init = func(num, init); 125 | } 126 | return init; 127 | } 128 | } 129 | let addEx = acc(addb, 0); 130 | console.log(addEx(1, 2, 4)); // 7 131 | let mulEx = acc(mulb, 1); 132 | console.log(mulEx(1, 2, 4)); // 8 133 | 134 | // 18. accPartial -------------------------------------------------------------------------------- /Solutions/fun_solution_mla.js: -------------------------------------------------------------------------------- 1 | /** 2 | * indentity(x) return the same parameter as was past in 3 | * 4 | * @param {any} x 5 | * 6 | * @returns {any} 7 | */ 8 | const identity = x => x; 9 | 10 | /** 11 | * addb(a, b) returns the sum of a and b 12 | * 13 | * @param {Number} a 14 | * @param {Number} b 15 | * 16 | * @returns {Number} 17 | */ 18 | const addb = (a, b) => a + b; 19 | 20 | /** 21 | * subb(a, b) returns the difference between a and b 22 | * 23 | * @param {Number} a 24 | * @param {Number} b 25 | * 26 | * @returns {Number} 27 | */ 28 | const subb = (a, b) => a - b; 29 | 30 | /** 31 | * mulb(a, b) returns the product of a and b 32 | * 33 | * @param {Number} a 34 | * @param {Number} b 35 | * 36 | * @returns {Number} 37 | */ 38 | const mulb = (a, b) => a * b; 39 | 40 | /** 41 | * minb(a, b) returns the minimum of a and b 42 | * 43 | * @param {Number} a 44 | * @param {Number} b 45 | * 46 | * @returns {Number} 47 | */ 48 | const minb = (a, b) => a < b ? a : b; 49 | 50 | /** 51 | * maxb(a, b) returns the maximum of a and b 52 | * 53 | * @param {Number} a 54 | * @param {Number} b 55 | * 56 | * @returns {Number} 57 | */ 58 | const maxb = (a, b) => a > b ? a : b; 59 | 60 | /** 61 | * add(...nums) returns the sum of all numbers in nums 62 | * 63 | * @param {...Number} nums 64 | * 65 | * @returns {Number} 66 | */ 67 | const add = (...nums) => nums.reduce((prev, cur) => prev + cur, 0); 68 | 69 | /** 70 | * mul(...nums) returns the product of all numbers in nums 71 | * 72 | * @param {...Number} nums 73 | * 74 | * @returns {Number} 75 | */ 76 | const mul = (...nums) => nums.reduce((prev, cur) => prev * cur, 1); 77 | 78 | -------------------------------------------------------------------------------- /Solutions/giuffrida_solutions.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | const identity = x => x; 3 | 4 | // Write a binary function addb that takes two numbers and returns their sum 5 | const addb = (a, b) => a + b; 6 | 7 | // Write a binary function subb that takes two numbers and returns their difference 8 | const subb = (a, b) => a - b; 9 | 10 | // Write a binary function mulb that takes two numbers and returns their product 11 | const mulb = (a, b) => a * b; 12 | 13 | // Write a binary function minb that takes two numbers and returns the smaller one 14 | const minb = (a, b) => a > b ? b : a; 15 | 16 | // Write a binary function maxb that takes two numbers and returns the larger one 17 | const maxb = (a, b) => a > b ? a : b; 18 | 19 | // Write a function add that is generalized for any amount of arguments 20 | const add = (...nums) => nums.reduce((acc, number) => acc + number); 21 | 22 | // Write a function sub that is generalized for any amount of arguments 23 | const sub = (...nums) => nums.reduce((acc, num) => acc - num); 24 | 25 | // Write a function mul that is generalized for any amount of arguments 26 | const mul = (...nums) => nums.reduce((acc, num) => acc * num); 27 | 28 | // Write a function min that is generalized for any amount of arguments 29 | const min = (...nums) => Math.min(...nums); 30 | 31 | // Write a function max that is generalized for any amount of arguments 32 | const max = (...nums) => Math.max(...nums); 33 | 34 | // Write a function addRecurse that is the generalized add function but uses recursion 35 | const addRecurse = (...nums) => nums.length < 1 ? 0 : nums[0] + addRecurse(...nums.slice(1)); 36 | 37 | // Write a function mulRecurse that is the generalized mul function but uses recursion 38 | const mulRecurse = (...nums) => nums.length < 1 ? 1 : nums[0] * mulRecurse(...nums.slice(1)); 39 | 40 | // Write a function minRecurse that is the generalized min function but uses recursion 41 | const minRecurse = (...nums) => nums.length === 1 ? nums[0] : nums[0] < minRecurse(...nums.slice(1)) ? nums[0] : minRecurse(...nums.slice(1)); 42 | 43 | // Write a function maxRecurse that is the generalized max function but uses recursion 44 | const maxRecurse = (...nums) => nums.length === 1 ? nums[0] : nums[0] > maxRecurse(...nums.slice(1)) ? nums[0] : maxRecurse(...nums.slice(1)); 45 | 46 | 47 | module.exports = { 48 | identity, 49 | addb, 50 | subb, 51 | mulb, 52 | minb, 53 | maxb, 54 | add, 55 | sub, 56 | mul, 57 | min, 58 | max, 59 | addRecurse, 60 | mulRecurse, 61 | minRecurse, 62 | maxRecurse 63 | } 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /Solutions/goosNJuice_Solution.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | export const identity = (argument) => argument; 3 | 4 | //Write a binary function addb that takes two numbers and returns their sum 5 | export const addb = (a, b) => a + b; 6 | 7 | // Write a binary function subb that takes two numbers and returns their difference 8 | export const subb = (a, b) => a - b; 9 | 10 | // Write a binary function mulb that takes two numbers and returns their product 11 | export const mulb = (a, b) => a*b; 12 | 13 | // Write a binary function minb that takes two numbers and returns the smaller one 14 | export const minb = (a, b) => a < b ? a : b; 15 | 16 | // Write a binary function maxb that takes two numbers and returns the larger one 17 | export const maxb = (a, b) => a > b ? a : b; 18 | -------------------------------------------------------------------------------- /Solutions/hari_krishna_js_fun.js: -------------------------------------------------------------------------------- 1 | const identity = (x) => x; 2 | 3 | const addb = (a, b) => a + b; 4 | 5 | const subb = (a, b) => a - b; 6 | 7 | const mulb = (a, b) => a * b; 8 | 9 | const minb = (a, b) => (a > b ? b : a); 10 | 11 | const maxb = (a, b) => (a > b ? a : b); 12 | 13 | const add = (...nums) => { 14 | return nums.reduce((acc, num) => acc + num); 15 | }; 16 | 17 | const sub = (...nums) => { 18 | return nums.reduce((acc, num) => acc - num); 19 | }; 20 | const mul = (...nums) => { 21 | return nums.reduce((acc, num) => acc * num); 22 | }; 23 | const min = (...nums) => { 24 | return Math.min(...nums); 25 | }; 26 | 27 | const max = (...nums) => { 28 | return Math.max(...nums); 29 | }; 30 | 31 | module.exports = { 32 | identity, 33 | addb, 34 | subb, 35 | mulb, 36 | minb, 37 | maxb, 38 | add, 39 | sub, 40 | mul, 41 | min, 42 | max, 43 | }; 44 | -------------------------------------------------------------------------------- /Solutions/hirasolutions.js: -------------------------------------------------------------------------------- 1 | // 1. Returns the argument 2 | const identity = (arg) => arg; 3 | identity('Hi, Im Hira'); 4 | 5 | //Sum of two numbers 6 | 7 | const addNum = (one, two) 8 | => one + two; 9 | addNum(one, two); 10 | 11 | addNum(9,8); 12 | 13 | //Takes two numbers and returns difference 14 | 15 | const subNum = (one, two) 16 | => one - two; 17 | subNum(one, two); 18 | 19 | subNum(4,8); 20 | 21 | //Takes two numbers and returns product 22 | const mulNum = (one, two) 23 | => one * two; 24 | mulNum(one, two); 25 | 26 | mulNum(4,8); -------------------------------------------------------------------------------- /Solutions/ielisman.js: -------------------------------------------------------------------------------- 1 | const identity = (x) => x; 2 | const addb = (a,b) => a+b; 3 | const subb = (a,b) => a-b; 4 | const mulb = (a,b) => a*b; 5 | const minb = (a,b) => a a>b?a:b; 7 | const add = (...nums) => nums.reduce ((a,b)=>addb(a,b),0); 8 | const sub = (...nums) => nums.reduce ((a,b)=>subb(a,b),0); 9 | const mul = (...nums) => nums.reduce ((a,b)=>mulb(a,b),1); 10 | const min = (...nums) => nums.reduce ((a,b)=>minb(a,b)); 11 | const max = (...nums) => nums.reduce ((a,b)=>maxb(a,b)); 12 | const addRecurse = (...nums) => nums.length===1?nums[0]:nums.pop()+addRecurse(...nums); 13 | const mulRecurse = (...nums) => nums.length===1?nums[0]:nums.pop()*mulRecurse(...nums); 14 | const minRecurse = (...nums) => nums.length===1?nums[0]:minb(nums.pop(),minRecurse(...nums)); 15 | const maxRecurse = (...nums) => nums.length===1?nums[0]:maxb(nums.pop(),maxRecurse(...nums)); 16 | //const not = (f) => (...args) => !f(...args); // to be continued ... 17 | 18 | module.exports = { 19 | identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse/*, 20 | not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, 21 | curryb, curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, 22 | composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, 23 | elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, 24 | fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, 25 | addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, 26 | mapRecurse, filterRecurse, */}; -------------------------------------------------------------------------------- /Solutions/ishangupta_solution.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | const identity = (x) => x 3 | 4 | // Write a binary function addb that takes two numbers and returns their sum 5 | const addb = (a, b) => a + b 6 | 7 | // Write a binary function subb that takes two numbers and returns their difference 8 | const subb = (a, b) => a - b 9 | 10 | // Write a binary function mulb that takes two numbers and returns their product 11 | const mulb = (a, b) => a * b 12 | 13 | // Write a binary function minb that takes two numbers and returns the smaller one 14 | const minb = (a, b) => (a < b ? a : b) 15 | 16 | // Write a binary function maxb that takes two numbers and returns the larger one 17 | const maxb = (a, b) => (a > b ? a : b) 18 | 19 | // Write a function add that is generalized for any amount of arguments 20 | const add = (...nums) => nums.reduce((a, b) => a + b) 21 | 22 | // Write a function sub that is generalized for any amount of arguments 23 | const sub = (...nums) => nums.reduce((a, b) => a - b) 24 | 25 | // Write a function mul that is generalized for any amount of arguments 26 | const mul = (...nums) => nums.reduce((a, b) => a * b) 27 | 28 | // Write a function min that is generalized for any amount of arguments 29 | const min = (...nums) => Math.min(...nums) 30 | 31 | // Write a function max that is generalized for any amount of arguments 32 | const max = (...nums) => Math.max(...nums) 33 | 34 | // Write a function addRecurse that is the generalized add function but uses recursion 35 | const addRecurse = (...nums) => nums.length===1 ? nums[0] : nums.pop() + addRecurse(...nums) 36 | 37 | // Write a function mulRecurse that is the generalized mul function but uses recursion 38 | const mulRecurse = (...nums) => nums.length===1 ? nums[0] : nums.pop() * mulRecurse(...nums) 39 | 40 | 41 | // Write a function not that takes a function and returns the negation of its result 42 | const not = func => (...args) => {return !(func(...args))} 43 | 44 | // Write a function acc that takes a function and an initial value and returns a function that runs the initial function on each argument, accumulating the result 45 | 46 | 47 | // Write a function set that is given a list of arguments and returns an array with all duplicates removed 48 | const set = (...args) => [...new Set(args)] 49 | 50 | // Write a function addf that adds from two invocations 51 | const addf = (a) => (b) => a+b 52 | 53 | // Write a function liftf that takes a binary function, and makes it callable with two invocations 54 | const liftf = (f) => (a) => (b) => f(a,b) 55 | 56 | // Write a function twiceUnary that takes a binary function and returns a unary function that passes its argument to the binary function twice 57 | const twiceUnary = binary => a => binary(a,a); 58 | 59 | // Use the function twiceUnary to create the doubl function 60 | const doubl = (x) => twiceUnary(addb)(x) 61 | 62 | // Use the function twiceUnary to create the square function 63 | const square = (x) => twiceUnary(mulb)(x) 64 | 65 | // Write a function twice that is generalized for any amount of arguments 66 | const twice = x => (...args) => x(...args, ...args) 67 | 68 | // Write a function reverseb that reverses the arguments of a binary function 69 | const reverseb = binary => (a, b) => binary(b,a) 70 | 71 | // Write a function reverse that is generalized for any amount of arguments 72 | const reverse = func => (...args) => func(...args.reverse()) 73 | 74 | // Write a function composeuTwo that takes two unary functions and returns a unary function that calls them both 75 | const composeuTwo = (unary1, unary2) => x => unary2(unary1(x)) 76 | 77 | 78 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry , inc, twiceUnary, doubl, square , twice, reverseb, reverse, composeuTwo}; 79 | 80 | -------------------------------------------------------------------------------- /Solutions/js-fun-practice-vinavoovoo.js: -------------------------------------------------------------------------------- 1 | // ZTM JS_Fun_Practice - Vincent 2 | 3 | // 1. takes an argument and returns it 4 | const identity = (x) => x; 5 | 6 | // 2. returns sum of two numbers 7 | const addb = (a, b) => a + b; 8 | 9 | // 3. returns difference of two numbers 10 | const subb = (a, b) => a - b; 11 | 12 | // 4. returns product of two numbers 13 | const mulb = (a, b) => a * b; 14 | 15 | // 5. takes two numbers and returns whichever is smaller 16 | const minb = (a, b) => { 17 | if (a > b) { 18 | return b; 19 | } else { 20 | return a; 21 | } 22 | } 23 | 24 | // 6. takes two numbers and returns whichever is larger 25 | const maxb = (a, b) => { 26 | if (a < b) { 27 | return b; 28 | } else { 29 | return a; 30 | } 31 | } 32 | 33 | // 7. addition function for any amount of arguments 34 | const add = (...args) => { 35 | return args.reduce((acc, arg) => { 36 | return acc + arg; 37 | }); 38 | } 39 | 40 | // 8. subtraction function ... unlimited arguments 41 | const sub = (...args) => { 42 | return args.reduce((acc, arg) => { 43 | return acc - arg; 44 | }); 45 | } 46 | 47 | // 9. multiplication function ... unlimited arguments 48 | const mul = (...args) => { 49 | return args.reduce((acc, arg) => { 50 | return acc * arg; 51 | }); 52 | } 53 | 54 | // 10. returns smallest number ... unlimited arguments 55 | const min = (...args) => { 56 | let min = args[0]; 57 | for (arg of args) { 58 | if (min > arg) { 59 | min = arg; 60 | } 61 | } 62 | return min; 63 | } 64 | 65 | // 11. returns largest number ... unlimited arguments 66 | const max = (...args) => { 67 | let max = args[0]; 68 | for (arg of args) { 69 | if (max < arg) { 70 | max = arg; 71 | } 72 | } 73 | return max; 74 | } 75 | 76 | // 12. addition function using recursion 77 | const addRecurse = (...nums) => { 78 | if (nums.length === 1) { 79 | return nums[0]; 80 | } 81 | return nums.pop() + addRecurse(...nums); 82 | } 83 | 84 | // 13. multiplication function using recursion 85 | const mulRecurse = (...nums) => { 86 | if (nums.length === 1) { 87 | return nums[0]; 88 | } 89 | return nums.pop() * mulRecurse(...nums); 90 | } 91 | 92 | // 14. returns smallest number using recursion 93 | const minRecurse = (...nums) => { 94 | if (nums.length === 1) { 95 | return nums[0]; 96 | } else if (nums[0] > nums[1]) { 97 | nums.shift(); 98 | } else { 99 | nums[1] = nums[0]; 100 | nums.shift(); 101 | } 102 | return minRecurse(...nums); 103 | } 104 | 105 | // 15. returns largest number using recursion 106 | const maxRecurse = (...nums) => { 107 | if (nums.length === 1) { 108 | return nums[0]; 109 | } else if (nums[0] < nums[1]) { 110 | nums.shift(); 111 | } else { 112 | nums[1] = nums[0]; 113 | nums.shift(); 114 | } 115 | return maxRecurse(...nums); 116 | } 117 | 118 | // 16. takes a function as an argument and returns the opposite Bool 119 | const not = func =>(...args) => { 120 | return !Boolean(func(...args)); 121 | } 122 | 123 | 124 | // 17. takes a function and initial value and returns a function that 125 | // runs the initial function on each argument, accumulating the result 126 | const acc = (func, begin) => (...args) => { 127 | let c = begin; 128 | for (i of args) { 129 | c = (func(c, i)); 130 | } 131 | return c; 132 | } 133 | 134 | // 18. still working on it... takes in a function, start, and end, and returns a function that 135 | // creates a subset of array, with function applied to that subset 136 | const add = (...args) => { 137 | return args.reduce((acc, arg) => { 138 | return acc + arg; 139 | }); 140 | } 141 | 142 | const accPartial = (func, start, end) => (...args) => { 143 | return func([args[start], args[end]]); 144 | } 145 | 146 | accPartial(add,1,10)() 147 | 148 | 149 | ////////////////For Reference////////////////// 150 | const mapArray = array.map(num => { 151 | return num * 2 152 | }) 153 | const reduceArray = array.reduce((accumulator, num) => { 154 | return accumulator + num; 155 | }, 100); 156 | /////////////////////////////////////////////// 157 | -------------------------------------------------------------------------------- /Solutions/justin2172021_solutions.js: -------------------------------------------------------------------------------- 1 | const identity = (arg) => { 2 | return arg; 3 | } 4 | 5 | const addb = (a, b) => { 6 | return a + b; 7 | } 8 | 9 | const subb = (a, b) => { 10 | return a - b; 11 | } 12 | 13 | const mulb = (a, b) => { 14 | return a * b; 15 | } 16 | 17 | const minb = (a, b) => { 18 | return a > b ? b : a; 19 | } 20 | 21 | const maxb = (a, b) => { 22 | return a > b ? a: b; 23 | } 24 | 25 | const add = (...nums) => { 26 | let sum = 0; 27 | for (let i = 0; i < nums.length; i++) { 28 | sum += nums[i]; 29 | } 30 | return sum; 31 | } 32 | 33 | const sub = (...nums) => { 34 | let subt = nums[0]; 35 | for (let i = 1; i < nums.length; i++) { 36 | subt -= nums[i]; 37 | } 38 | return subt; 39 | } 40 | 41 | const mul = (...nums) => { 42 | let prod = 1; 43 | for (let i = 1; i < nums.length; i++) { 44 | prod *= nums[i]; 45 | } 46 | return prod; 47 | } 48 | 49 | const min = (...nums) => { 50 | let less = nums[0]; 51 | for (let i = 1; i < nums.length; i++) { 52 | less < nums[i] ? less = less : less = nums[i]; 53 | } 54 | return less; 55 | } 56 | 57 | const max = (...nums) => { 58 | let bigger = nums[0]; 59 | for (let i = 1; i < nums.length; i++) { 60 | bigger > nums[i] ? bigger = bigger : bigger = nums[i]; 61 | } 62 | return bigger; 63 | } 64 | 65 | const addRecurse = (...nums) => { 66 | if (nums.length < 1) { 67 | return 0; 68 | } 69 | 70 | if (nums.length === 1){ 71 | return nums[0]; 72 | } 73 | return nums.pop() + addRecurse(...nums); 74 | } 75 | 76 | const mulRecurse = (...nums) => { 77 | if (nums.length < 1) { 78 | return 0; 79 | } 80 | 81 | if (nums.length === 1) { 82 | return nums[0]; 83 | } 84 | return nums.pop() * mulRecurse(...nums); 85 | } 86 | 87 | const minRecurse = (...nums) => { 88 | if (nums.length < 1) { 89 | return 0; 90 | } 91 | 92 | if (nums.length === 1) { 93 | return nums[0]; 94 | } 95 | return minb(nums[0], minRecurse(...nums.slice(1))); 96 | } 97 | 98 | const maxRecurse = (...nums) => { 99 | if (nums.length < 1) { 100 | return 0; 101 | } 102 | 103 | if (nums.length === 1) { 104 | return nums[0]; 105 | } 106 | return maxb(nums[0], maxRecurse(...nums.slice(1))); 107 | } 108 | 109 | module.exports = { 110 | identity, 111 | addb, 112 | subb, 113 | mulb, 114 | minb, 115 | maxb, 116 | add, 117 | sub, 118 | mul, 119 | min, 120 | max, 121 | addRecurse, 122 | mulRecurse, 123 | minRecurse, 124 | maxRecurse, 125 | // not, 126 | // acc, 127 | // accPartial, 128 | // accRecurse, 129 | // fill, 130 | // fillRecurse, 131 | // set, 132 | // identityf, 133 | // addf, 134 | // liftf, 135 | // pure, 136 | // curryb, 137 | // curry, 138 | // inc, 139 | // twiceUnary, 140 | // doubl, 141 | // square, 142 | // twice, 143 | // reverseb, 144 | // reverse, 145 | // composeuTwo, 146 | // composeu, 147 | // composeb, 148 | // composeTwo, 149 | // compose, 150 | // limitb, 151 | // limit, 152 | // genFrom, 153 | // genTo, 154 | // genFromTo, 155 | // elementGen, 156 | // element, 157 | // collect, 158 | // filter, 159 | // filterTail, 160 | // concatTwo, 161 | // concat, 162 | // concatTail, 163 | // gensymf, 164 | // gensymff, 165 | // fibonaccif, 166 | // counter, 167 | // revocableb, 168 | // revocable, 169 | // extract, 170 | // m, 171 | // addmTwo, 172 | // addm, 173 | // liftmbM, 174 | // liftmb, 175 | // liftm, 176 | // exp, 177 | // expn, 178 | // addg, 179 | // liftg, 180 | // arrayg, 181 | // continuizeu, 182 | // continuize, 183 | // vector, 184 | // exploitVector, 185 | // vectorSafe, 186 | // pubsub, 187 | // mapRecurse, 188 | // filterRecurse, 189 | }; -------------------------------------------------------------------------------- /Solutions/kciccolella_solutions.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | function identity(arg) { 3 | return arg; 4 | } 5 | 6 | // Write a binary function addb that takes two numbers and returns their sum 7 | function addb(num1, num2) { 8 | return num1 + num2; 9 | } 10 | 11 | module.exports = { 12 | identity, 13 | addb, 14 | // subb, 15 | // mulb, 16 | // minb, 17 | // maxb, 18 | // add, 19 | // sub, 20 | // mul, 21 | // min, 22 | // max, 23 | // addRecurse, 24 | // mulRecurse, 25 | // minRecurse, 26 | // maxRecurse, 27 | // not, 28 | // acc, 29 | // accPartial, 30 | // accRecurse, 31 | // fill, 32 | // fillRecurse, 33 | // set, 34 | // identityf, 35 | // addf, 36 | // liftf, 37 | // pure, 38 | // curryb, 39 | // curry, 40 | // inc, 41 | // twiceUnary, 42 | // doubl, 43 | // square, 44 | // twice, 45 | // reverseb, 46 | // reverse, 47 | // composeuTwo, 48 | // composeu, 49 | // composeb, 50 | // composeTwo, 51 | // compose, 52 | // limitb, 53 | // limit, 54 | // genFrom, 55 | // genTo, 56 | // genFromTo, 57 | // elementGen, 58 | // element, 59 | // collect, 60 | // filter, 61 | // filterTail, 62 | // concatTwo, 63 | // concat, 64 | // concatTail, 65 | // gensymf, 66 | // gensymff, 67 | // fibonaccif, 68 | // counter, 69 | // revocableb, 70 | // revocable, 71 | // extract, 72 | // m, 73 | // addmTwo, 74 | // addm, 75 | // liftmbM, 76 | // liftmb, 77 | // liftm, 78 | // exp, 79 | // expn, 80 | // addg, 81 | // liftg, 82 | // arrayg, 83 | // continuizeu, 84 | // continuize, 85 | // vector, 86 | // exploitVector, 87 | // vectorSafe, 88 | // pubsub, 89 | // mapRecurse, 90 | // filterRecurse, 91 | }; -------------------------------------------------------------------------------- /Solutions/khizarhashmi119.js: -------------------------------------------------------------------------------- 1 | /** 2 | * identity(x) returns the same argument. 3 | * 4 | * @param {*} x 5 | * 6 | * @returns {*} 7 | */ 8 | const identity = (x) => x; 9 | 10 | /** 11 | * addb(a, b) returns the sum of a and b. 12 | * 13 | * @param {Number} a 14 | * @param {Number} b 15 | * 16 | * @returns {Number} 17 | */ 18 | const addb = (a, b) => a + b; 19 | 20 | /** 21 | * subb(a, b) returns the difference of a and b. 22 | * 23 | * @param {Number} a 24 | * @param {Number} b 25 | * 26 | * @returns {Number} 27 | */ 28 | const subb = (a, b) => a - b; 29 | 30 | /** 31 | * mulb(a, b) returns the product of a and b. 32 | * 33 | * @param {Number} a 34 | * @param {Number} b 35 | * 36 | * @returns {Number} 37 | */ 38 | const mulb = (a, b) => a * b; 39 | 40 | /** 41 | * min(a, b) returns the min of a and b. 42 | * 43 | * @param {Number} a 44 | * @param {Number} b 45 | * 46 | * @returns {Number} 47 | */ 48 | const minb = (a, b) => a > b ? b : a; 49 | 50 | /** 51 | * maxb(a, b) returns the max of a and b. 52 | * 53 | * @param {Number} a 54 | * @param {Number} b 55 | * 56 | * @returns {Number} 57 | */ 58 | const maxb = (a, b) => a > b ? a : b; 59 | 60 | /** 61 | * add(...nums) returns the sum of nums. 62 | * 63 | * @param {...Number} nums 64 | * 65 | * @returns {Number} 66 | */ 67 | const add = (...nums) => nums.reduce((total, num) => total + num); 68 | 69 | /** 70 | * sub(...nums) returns the diff of nums. 71 | * 72 | * @param {...Number} nums 73 | * 74 | * @returns {Number} 75 | */ 76 | const sub = (...nums) => nums.reduce((acc, num) => acc - num); 77 | 78 | /** 79 | * mul(...nums) returns the product of nums. 80 | * 81 | * @param {...Number} nums 82 | * 83 | * @returns {Number} 84 | */ 85 | const mul = (...nums) => nums.reduce((acc, num) => acc * num); 86 | 87 | /** 88 | * min(...nums) returns the min of nums. 89 | * 90 | * @param {...Number} nums 91 | * 92 | * @returns {Number} 93 | */ 94 | const min = (...nums) => nums.reduce((min, num) => min < num ? min : num); 95 | 96 | /** 97 | * max(...nums) returns the max of nums. 98 | * 99 | * @param {...Number} nums 100 | * 101 | * @returns {Number} 102 | */ 103 | const max = (...nums) => nums.reduce((max, num) => (max > num ? max : num)); 104 | 105 | /** 106 | * addRecurse(...nums) returns the sum of nums. 107 | * 108 | * @param {...Number} nums 109 | * 110 | * @returns {Number} 111 | */ 112 | const addRecurse = (...nums) => { 113 | if(nums.length === 1) { 114 | return nums[0]; 115 | } else { 116 | const num = nums.shift(); 117 | return num + addRecurse(...nums); 118 | } 119 | } 120 | 121 | /** 122 | * mulRecurse(...nums) returns the product of nums. 123 | * 124 | * @param {...Number} nums 125 | * 126 | * @returns {Number} 127 | */ 128 | const mulRecurse = (...nums) => { 129 | if (nums.length === 1) { 130 | return nums[0]; 131 | } else { 132 | const num = nums.shift(); 133 | return num * mulRecurse(...nums); 134 | } 135 | }; 136 | 137 | /** 138 | * minRecurse(...nums) returns the min. of nums. 139 | * 140 | * @param {...Number} nums 141 | * 142 | * @returns {Number} 143 | */ 144 | const minRecurse = (...nums) => { 145 | if (nums.length === 1) { 146 | return nums[0]; 147 | } else { 148 | const num1 = nums.shift(); 149 | num2 = minRecurse(...nums); 150 | return num1 < num2 ? num1 : num2; 151 | } 152 | }; 153 | 154 | /** 155 | * maxRecurse(...nums) returns the max. of nums. 156 | * 157 | * @param {...Number} nums 158 | * 159 | * @returns {Number} 160 | */ 161 | const maxRecurse = (...nums) => { 162 | if (nums.length === 1) { 163 | return nums[0]; 164 | } else { 165 | const num1 = nums.shift(); 166 | num2 = maxRecurse(...nums); 167 | return num1 > num2 ? num1 : num2; 168 | } 169 | }; 170 | 171 | /** 172 | * fill(num) returns the array 173 | * 174 | * @param {Number} num 175 | * 176 | * @returns {Array} 177 | */ 178 | const fill = (num) => { 179 | const arr = []; 180 | 181 | for (let i = 0; i < num; i++) { 182 | arr[i] = num; 183 | } 184 | 185 | return arr; 186 | } 187 | 188 | module.exports = { 189 | identity, 190 | addb, 191 | subb, 192 | mulb, 193 | minb, 194 | maxb, 195 | add, 196 | sub, 197 | mul, 198 | min, 199 | max, 200 | addRecurse, 201 | mulRecurse, 202 | minRecurse, 203 | maxRecurse, 204 | fill, 205 | }; -------------------------------------------------------------------------------- /Solutions/kma_solutions.js: -------------------------------------------------------------------------------- 1 | function identity(x) { 2 | return x; 3 | } 4 | 5 | const addb = (a,b) => a+b; 6 | const subb = (a,b) => a-b; 7 | const mulb = (a,b) => a*b; 8 | 9 | 10 | module.exports = { identity, addb, subb, mulb }; 11 | // minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, }; -------------------------------------------------------------------------------- /Solutions/kunalprakash1309.js: -------------------------------------------------------------------------------- 1 | // takes an argument and returns that argument 2 | const identity = (x) => x; 3 | 4 | identity('Hello, World') ; // Hello, World 5 | 6 | 7 | // takes two numbers and returns their sum 8 | const addb = (a, b) => a + b; 9 | 10 | addb(3, 5); // 8 11 | 12 | 13 | // takes two numbers and returns their difference 14 | const subb = (a, b) => a - b; 15 | 16 | subb(20, 5) // 15 17 | 18 | 19 | // takes two numbers and returns their product 20 | const mulb = (a, b) => a * b; 21 | 22 | mulb(4, 3) // 12 23 | 24 | 25 | // takes two numbers and returns the smaller one 26 | const minb = (a, b) => a < b ? a : b; 27 | 28 | minb(12, 10) // 10 29 | 30 | 31 | // takes two numbers and returns the larger one 32 | const maxb = (a, b) => a > b ? a : b; 33 | 34 | maxb(20, 25) // 25 35 | 36 | 37 | // add that is genralized for any amount of arguments 38 | const add = (...nums) => nums.reduce((acc, num) => {return acc + num}, 0); 39 | 40 | add(1, 2, 3) // 6 41 | 42 | 43 | // sub that is generalized for any amount of arguments 44 | const sub = (...nums) => { 45 | let result = nums[0]; 46 | for (let i = 1; i < nums.length; i++){ 47 | result = result - nums[i]; 48 | } 49 | return result; 50 | } 51 | 52 | sub(100, 50, 25) // 25 53 | 54 | 55 | // mul that is genralized for any amount of arguments 56 | const mul = (...nums) => nums.reduce((acc, num) => {return acc * num}, 1) 57 | 58 | mul(6, 5, 4, 3, 2, 1) // 720 59 | 60 | 61 | // min that is genralized for any amount of arguments 62 | const min = (...nums) => { 63 | let minimum = nums[0]; 64 | for(let i = 1; i < nums.length; i++){ 65 | minimum = minimum < nums[i] ? minimum : nums[i]; 66 | } 67 | return minimum 68 | } 69 | 70 | min(30, 40, 55, 10) // 10 71 | 72 | 73 | // max that is generalized for any amount of arguments 74 | const max = (...nums) => { 75 | let maximum = nums[0]; 76 | for(let i = 1; i < nums.length; i++){ 77 | maximum = maximum > nums[i] ? maximum : nums[i]; 78 | } 79 | return maximum 80 | } 81 | 82 | max(30, 40, 55, 10) // 55 83 | 84 | 85 | // addRecurse that is generalized add function but uses recursion 86 | function addRecurse(...nums) { 87 | if (nums.length < 1) { 88 | return 0; 89 | } 90 | if (nums.length === 1) { 91 | return nums[0]; 92 | } 93 | return nums[0] + addRecurse(...nums.slice(1)); 94 | } 95 | 96 | addRecurse(1, 5, 6) // 12 97 | 98 | 99 | // mulRecurse that is the generalized mul function but uses recursion 100 | const mulRecurse = (...nums) => { 101 | if (nums.length < 1) { 102 | return 0 103 | } 104 | 105 | if (nums.length == 1) { 106 | return nums[0] 107 | } 108 | 109 | return nums[0] * mulRecurse(...nums.slice(1)) 110 | } 111 | 112 | mulRecurse(1, 2, 4) // 8 113 | 114 | // minRecurse that is the generalized min function but uses recursion 115 | const minRecurse = (...nums) => { 116 | if (nums.length < 1) { 117 | return 'Empty Array' 118 | } 119 | 120 | if (nums.length === 1) { 121 | return nums[0] 122 | } 123 | 124 | return nums[0] < minRecurse(...nums.slice(1)) 125 | ? nums[0] 126 | : minRecurse(...nums.slice(1)) 127 | } 128 | 129 | minRecurse(1, 2, 6, 7, -6, 9, 44, 4) // -6 130 | 131 | 132 | // maxRecurse that is the generalized max function but uses recursion 133 | const maxRecurse = (...nums) => { 134 | if (nums.length < 1) { 135 | return 'Empty Array' 136 | } 137 | 138 | if (nums.length === 1) { 139 | return nums[0] 140 | } 141 | 142 | return maxb(nums[0], maxRecurse(...nums.slice(1))) 143 | } 144 | 145 | maxRecurse(2, 6, 7, -6, 9, 44, 4) // 44 146 | 147 | // Write a function not that takes a function and returns the negation of its result 148 | const not = (func) => { 149 | return (...args) => !(func(...args)) 150 | } 151 | 152 | //Write a function acc that takes a function and an initial value and returns a function that runs the initial function on each argument, accumulating the result 153 | 154 | const acc = (func, initial) => { 155 | return (...args) => { 156 | for (item of args){ 157 | initial += func(item); 158 | } 159 | return initial; 160 | } 161 | } 162 | 163 | //Write a function accPartial that takes in a function, a start index, and an end index, and returns a function that accumulates a subset of its arguments by applying the given function to all elements between start and end. 164 | 165 | const accPartial = (func, start, end) => { 166 | let accum = 0; 167 | return (...args) => { 168 | for (let i = start; i< start+end; i++){ 169 | accum += func(args[i]); 170 | } 171 | return accum 172 | } 173 | } 174 | 175 | //Write a function fill that takes a number and returns an array with that many numbers equal to the given number 176 | 177 | const fill = (num) => { 178 | let nums = []; 179 | for (let i=0; i { 188 | if(list.length===num){ 189 | return list; 190 | } 191 | else{ 192 | list.push(num); 193 | return fillRecurse(num,list); 194 | } 195 | }; 196 | 197 | //Write a function set that is given a list of arguments and returns an array with all duplicates removed 198 | 199 | const set = (...args) => { 200 | let sett=[]; 201 | for (item of args){ 202 | if (sett.includes(item)){ 203 | 204 | } 205 | else { 206 | sett.push(item) 207 | } 208 | } 209 | return sett; 210 | } 211 | 212 | //Write a function identityf that takes an argument and returns a function that returns that argument 213 | 214 | const identityf = (x) =>{ 215 | return (x) => {x}; 216 | } 217 | 218 | // Write a function addf that adds from two invocations 219 | 220 | const addf = (x) => { 221 | return function(y) { 222 | return x + y; 223 | } 224 | } 225 | 226 | module.exports = { 227 | identity, 228 | addb, 229 | subbb, 230 | mulb, 231 | minb, 232 | maxb, 233 | add, 234 | sub, 235 | mul, 236 | min, 237 | max, 238 | addRecurse, 239 | mulRecurse, 240 | minRecurse, 241 | maxRecurse, 242 | not, 243 | acc, 244 | accRecusrse, 245 | fill, 246 | fillRecurse, 247 | set, 248 | identityf, 249 | addf 250 | }; -------------------------------------------------------------------------------- /Solutions/leykhan.js: -------------------------------------------------------------------------------- 1 | // At the bottom of your solution file, add 2 | 3 | // Write a function identity that takes an argument and returns that argument 4 | const identity = (x) => x; 5 | 6 | // Write a binary function addb that takes two numbers and returns their sum 7 | const addb = (a, b) => { 8 | if (typeof a === Number && typeof b === Number) { 9 | return a + b; 10 | } 11 | return "invalid input"; 12 | } 13 | 14 | // Write a binary function subb that takes two numbers and returns their difference? 15 | const subb = (a, b) => { 16 | if (typeof a === Number && typeof b === Number) { 17 | return a - b; 18 | } 19 | return "invalid input"; 20 | 21 | } 22 | 23 | module.exports = { 24 | identity, addb, subb, 25 | // mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, 26 | }; -------------------------------------------------------------------------------- /Solutions/luckynumber.js: -------------------------------------------------------------------------------- 1 | const database = 2 | [ 3 | { 4 | username: "Bobby", 5 | password: "secretpassword" 6 | }, 7 | 8 | { 9 | username: "Johnas", 10 | password: "secretpassword2", 11 | }, 12 | 13 | { 14 | username: "Martha", 15 | password: "secretpassword3", 16 | }, 17 | 18 | ] 19 | let userPrompt = prompt("what's your username?") 20 | let passwordPrompt = prompt("what's you password?") 21 | 22 | 23 | const ifUserIsValid = (user,pw) => { 24 | for (i=0;i { 35 | if (ifUserIsValid(user,pw)) { 36 | alert(luckyNumber) 37 | alert((Math.round(Math.random() * 10))) 38 | } else { 39 | alert("Sorry,wrong username or password") 40 | } 41 | } 42 | let luckyNumber = `Hi ${userPrompt}! Your lucky number for today is:` 43 | 44 | logIn(userPrompt,passwordPrompt) 45 | -------------------------------------------------------------------------------- /Solutions/luigi_solutions.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | const identity = (arg) => arg; 3 | 4 | //Write a binary function addb that takes two numbers and returns their sum 5 | const addb = (a, b) => a + b; 6 | 7 | // Write a binary function subb that takes two numbers and returns their difference 8 | const subb = (a, b) => a - b; 9 | 10 | // Write a binary function mulb that takes two numbers and returns their product 11 | const mulb = (a, b) => a * b; 12 | 13 | // Write a binary function minb that takes two numbers and returns the smaller one 14 | const minb = (a, b) => (a < b ? a : b); 15 | 16 | // Write a binary function maxb that takes two numbers and returns the larger one 17 | const maxb = (a, b) => (a > b ? a : b); 18 | 19 | // Write a function add that is generalized for any amount of arguments 20 | const add = (...nums) => { 21 | return nums.reduce((a, acc) => { 22 | return a + acc; 23 | }); 24 | }; 25 | 26 | // Write a function sub that is generalized for any amount of arguments 27 | const sub = (...nums) => { 28 | return nums.reduce((a, acc) => { 29 | return a - acc; 30 | }); 31 | }; 32 | 33 | //Write a function mul that is generalized for any amount of arguments 34 | const mul = (...num) => { 35 | return num.reduce((a, acc) => { 36 | return a * acc; 37 | }, 1); 38 | }; 39 | 40 | // Write a function min that is generalized for any amount of arguments 41 | const min = (...num) => { 42 | return num.reduce((a, b) => Math.min(a, b)); 43 | }; 44 | 45 | // Write a function max that is generalized for any amount of arguments 46 | const max = (...num) => { 47 | return num.reduce((a, b) => Math.max(a, b)); 48 | }; 49 | 50 | module.exports = { 51 | identity, 52 | addb, 53 | subb, 54 | mulb, 55 | minb, 56 | maxb, 57 | add, 58 | sub, 59 | mul, 60 | min, 61 | max, 62 | addRecurse, 63 | mulRecurse, 64 | minRecurse, 65 | maxRecurse, 66 | fill, 67 | }; 68 | -------------------------------------------------------------------------------- /Solutions/mathewtrSolution.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | 3 | const identity = function (x) { 4 | return x; 5 | }; 6 | 7 | // Write a binary function addb that takes two numbers and returns their sum 8 | 9 | const addb = function (a, b) { 10 | return a + b; 11 | }; 12 | 13 | // Write a binary function subb that takes two numbers and returns their difference 14 | 15 | const subb = function (a, b) { 16 | return a - b; 17 | }; 18 | 19 | //Write a binary function mulb that takes two numbers and returns their product 20 | 21 | const mulb = function (a, b) { 22 | return a * b; 23 | }; 24 | 25 | //Write a binary function minb that takes two numbers and returns the smaller one 26 | 27 | const minb = function (a, b) { 28 | return a < b ? a : b; 29 | }; 30 | 31 | //Write a binary function maxb that takes two numbers and returns the larger one 32 | 33 | const maxb = function (a, b) { 34 | return a > b ? a : b; 35 | }; 36 | 37 | //Write a function add that is generalized for any amount of arguments 38 | 39 | const add = function (...nums) { 40 | return nums.reduce((accumulator, currentNum) => { 41 | return accumulator + currentNum; 42 | }, 0); 43 | }; 44 | 45 | //Write a function sub that is generalized for any amount of arguments 46 | 47 | const sub = function (...nums) { 48 | return nums.reduce((accumulator, currentNum) => { 49 | return accumulator - currentNum; 50 | }); 51 | }; 52 | 53 | //Write a function mul that is generalized for any amount of arguments 54 | 55 | const mul = function (...nums) { 56 | return nums.reduce((accumulator, currentNum) => { 57 | return accumulator * currentNum; 58 | }); 59 | }; 60 | 61 | //Write a function min that is generalized for any amount of arguments 62 | 63 | const min = function (...nums) { 64 | return nums.reduce((accumulator, currentNum) => { 65 | return accumulator < currentNum ? accumulator : currentNum; 66 | }); 67 | }; 68 | 69 | //Write a function max that is generalized for any amount of arguments 70 | 71 | const max = function (...nums) { 72 | return nums.reduce((accumulator, currentNum) => { 73 | return accumulator > currentNum ? accumulator : currentNum; 74 | }); 75 | }; 76 | -------------------------------------------------------------------------------- /Solutions/mayank0255_solutions.js: -------------------------------------------------------------------------------- 1 | const identity = x => x; 2 | 3 | const addb = (a, b) => a + b; 4 | 5 | const subb = (a, b) => a - b ; 6 | 7 | const mulb = (a, b) => a * b; 8 | 9 | const minb = (a, b) => a < b ? a : b; 10 | 11 | const maxb = (a, b) => a > b ? a : b; 12 | 13 | const add = (...numbers) => numbers.reduce((total, num) => total + num); 14 | 15 | const sub = (...numbers) => numbers.reduce((total, num) => total - num); 16 | 17 | const mul = (...numbers) => numbers.reduce((total, num) => total * num); 18 | 19 | const min = (...numbers) => { 20 | let x = numbers[0]; 21 | numbers.forEach(number => { 22 | if (x > number) x = number; 23 | }); 24 | return x; 25 | } 26 | 27 | const max = (...numbers) => { 28 | let x = numbers[0]; 29 | numbers.forEach(number => { 30 | if (x < number) x = number; 31 | }); 32 | return x; 33 | } 34 | 35 | module.exports = { 36 | identity, 37 | addb, 38 | subb, 39 | mulb, 40 | minb, 41 | maxb, 42 | add, 43 | sub, 44 | mul, 45 | min, 46 | max 47 | }; -------------------------------------------------------------------------------- /Solutions/melipi_solutions.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | const identity = x => x; 3 | 4 | // Write a binary function addb that takes two numbers and returns their sum 5 | const addb = (a,b) => a + b; 6 | 7 | // Write a binary function subb that takes two numbers and returns their difference 8 | const subb = (a,b) => a - b; 9 | 10 | // Write a binary function mulb that takes two numbers and returns their product 11 | const mulb = (a,b) => a * b; 12 | 13 | // Write a binary function minb that takes two numbers and returns the smaller one 14 | const minb = (a,b) => a < b ? a : b; 15 | 16 | // Write a binary function maxb that takes two numbers and returns the larger one 17 | const maxb = (a,b) => a > b ? a : b; 18 | 19 | // Write a function add that is generalized for any amount of arguments 20 | const add = (...nums) => nums.reduce((acc,sum) => sum += acc); 21 | 22 | // Write a function sub that is generalized for any amount of arguments 23 | const sub = (...nums) => nums.reduce((acc,sum) => sum -= acc); 24 | 25 | // Write a function mul that is generalized for any amount of arguments 26 | const mul = (...nums) => nums.reduce((acc,sum) => sum *= acc); 27 | 28 | // Write a function min that is generalized for any amount of arguments 29 | const min = (...nums) => Math.min(...nums); 30 | 31 | // Write a function max that is generalized for any amount of arguments 32 | const max = (...nums) => Math.max(...nums); 33 | 34 | // Write a function addRecurse that is the generalized add function but uses recursion 35 | const addRecurse = (...nums) => 36 | (nums.length === 1) 37 | ? nums[0] 38 | : nums.pop() + addRecurse(...nums); 39 | 40 | // Write a function mulRecurse that is the generalized mul function but uses recursion 41 | const mulRecurse = (...nums) => 42 | (nums.length === 1) 43 | ? nums[0] 44 | : nums.pop() * mulRecurse(...nums); 45 | 46 | // Write a function minRecurse that is the generalized min function but uses recursion 47 | const minRecurse = (...nums) => { 48 | if (nums.length === 1) return nums[0]; 49 | return Math.min(nums.shift(), minRecurse(...nums)) 50 | } 51 | 52 | // Write a function maxRecurse that is the generalized max function but uses recursion 53 | const maxRecurse = (...nums) => { 54 | if (nums.length === 1) return nums[0]; 55 | return Math.max(nums.shift(), maxRecurse(...nums)) 56 | } 57 | 58 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, /*not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse,*/}; -------------------------------------------------------------------------------- /Solutions/michaelzwiener.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | // const identity = (argument => argument); 3 | // identity("Michael"); 4 | 5 | //Write a binary function addb that takes two numbers and returns their sum 6 | const addb = ((n1, n2) => n1+n2); 7 | addb(3,4); 8 | 9 | // Write a binary function subb that takes two numbers and returns their difference 10 | const subb = (n1, n2) => console.log(Math.abs(n1 - n2)); 11 | subb(5,7); 12 | 13 | // Write a binary function mulb that takes two numbers and returns their product 14 | const mulb = (n1, n2) => console.log(n1*n2); 15 | mulb(3,6); 16 | 17 | // Write a binary function minb that takes two numbers and returns the smaller one 18 | const minb = (n1, n2) => console.log(Math.min(n1, n2)); 19 | minb(4,7); 20 | 21 | // Write a binary function maxb that takes two numbers and returns the larger one 22 | const maxb = (n1, n2) => console.log(Math.max(n1, n2)); 23 | maxb(4,7); 24 | 25 | // Write a function add that is generalized for any amount of arguments 26 | let sum=0; 27 | const add = (arguments => arguments.forEach(element => sum+=element)); 28 | add([1,5,7,9]); 29 | 30 | // Write a function sub that is generalized for any amount of arguments 31 | let sum=100; 32 | const sub = (arguments => arguments.forEach(element => sum-=element)); 33 | sub([1,5,7,9]); 34 | 35 | //Write a function mul that is generalized for any amount of arguments 36 | // let sum=1; 37 | const mul = (arguments => arguments.forEach(element => sum = sum * element)); 38 | mul([1,5,7,9]); 39 | 40 | // Write a function min that is generalized for any amount of arguments 41 | const min = (arguments => console.log(Math.min(...arguments))); 42 | min([5,7,1,9]); 43 | 44 | // Write a function max that is generalized for any amount of arguments 45 | const max = (arguments => console.log(Math.max(...arguments))); 46 | max([5,7,1,9]); 47 | 48 | 49 | // I TAP OUT HERE FOR NOW // 50 | 51 | 52 | 53 | // Write a function addRecurse that is the generalized add function but uses recursion 54 | 55 | // Write a function mulRecurse that is the generalized mul function but uses recursion 56 | 57 | 58 | // Write a function minRecurse that is the generalized min function but uses recursion 59 | 60 | 61 | // Write a function maxRecurse that is the generalized max function but uses recursion 62 | 63 | 64 | // Write a function not that takes a function and returns the negation of its result 65 | 66 | 67 | // Write a function accPartial that takes in a function, a start index, and an end index, and returns a function that accumulates a subset of its arguments by applying the given function to all elements between start and end. 68 | 69 | 70 | // Write a function accRecurse that does what acc does but uses recursion 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | //module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, inc, twiceUnary, /*doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, */ }; -------------------------------------------------------------------------------- /Solutions/min-max.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | // addition of whole array into one number using rest operator 4 | 5 | function addb(...arg){ 6 | let count = 0; 7 | for (let arg of arguments) 8 | count += arg ; 9 | return count 10 | } 11 | 12 | let play = addb(1,2,3,4,6); 13 | 14 | console.log(play); 15 | 16 | 17 | 18 | // multiplication into one number--------------- 19 | 20 | function mulb(...numbers){ 21 | return numbers.reduce((a,b)=>a*b) 22 | } 23 | 24 | console.log(mulb(1,2,3)); 25 | 26 | // concat ------------------------ 27 | 28 | const a= [1,2,3,4]; 29 | 30 | const b= [6,7,8]; 31 | 32 | function concat(){ 33 | let check = b.concat(a); 34 | return check; 35 | } 36 | 37 | console.log(concat()); 38 | 39 | // min ----------------- 40 | 41 | function min(array){ 42 | return Math.min(...array); 43 | } 44 | 45 | 46 | let minimum = min([1,2,3,4,5]); 47 | 48 | console.log(minimum); 49 | 50 | // max -------------------- 51 | 52 | function max(array){ 53 | return Math.max(...array); 54 | } 55 | 56 | 57 | let maximum = max([1,2,3,4,5]); 58 | 59 | console.log(maximum); 60 | 61 | -------------------------------------------------------------------------------- /Solutions/mulRecurse.js: -------------------------------------------------------------------------------- 1 | //write a function mulRecurse that is a generalized mul functions but uses recursion 2 | 3 | //mul function 4 | const mul = (...nums) => { 5 | let answer = 1; 6 | for (let i = 0; i < nums.length; i++) { 7 | answer *= nums[i]; 8 | } 9 | return answer; 10 | } 11 | 12 | mul(1, 2, 3); 13 | 14 | //mulRecurse 1 15 | const mulRecurse1 = (...nums) => { 16 | const multiplyTwoIntegers = (a, b) => { 17 | if (b === 0 || a === 0) { 18 | return 0; 19 | } else if (b < 0) { 20 | return multiplyTwoIntegers(a, b + 1) - a; 21 | } 22 | return multiplyTwoIntegers(a, b - 1) + a; 23 | } 24 | let answer = 1; 25 | for (let i = 0; i < nums.length; i++) { 26 | answer = multiplyTwoIntegers(answer, nums[i]); 27 | } 28 | return answer; 29 | } 30 | 31 | //mulRecurse 2 32 | const mulRecurse2 = (...nums) => { 33 | if (nums.length < 1) { 34 | return 'enter values to be multiplied' 35 | } 36 | else if (nums.length === 1) { 37 | return nums[0]; 38 | } 39 | return nums[0] * mulRecurse2(...nums.slice(1)); 40 | } -------------------------------------------------------------------------------- /Solutions/my-solutions-GM.js: -------------------------------------------------------------------------------- 1 | //Write a function max that is generalised for any amount of arguments 2 | 3 | const max = (...nums) => {return nums.reduce((a,b) => a > b ? a : b);} 4 | console.log(max(7, 73, 100, 1, 35, -1, -9, 10, 67)) 5 | 6 | 7 | //Write a function addRecurse that is the generalised add function but uses recursion 8 | 9 | const addRecurse = (...nums) => { 10 | if (nums.length < 1) //base case 11 | return 0 12 | return nums[0] + addRecurse(...nums.slice(1)) 13 | } 14 | console.log(addRecurse(1,2,3,5)) 15 | 16 | // Write a function mulRecurse that is the generalized mul function but uses recursion 17 | 18 | const mulRecurse = (...nums) => { 19 | if (nums.length < 1) 20 | return 1; 21 | return nums[0] * (mulRecurse(...nums.slice(1))) 22 | } 23 | console.log(mulRecurse(1,2,3,4)) //should equal 24 -------------------------------------------------------------------------------- /Solutions/my-solutions-HN.js: -------------------------------------------------------------------------------- 1 | //add(...nums) 2 | let add = (...nums) =>{ 3 | return nums.reduce((accum, currentValue) =>{ 4 | return accum + currentValue; 5 | }, 0) 6 | } 7 | add(3, 4, 5); 8 | 9 | 10 | //min(...nums) 11 | let min = (...nums) => Math.min(...nums) 12 | min(2,4,1,6); 13 | 14 | 15 | //addRecurse(...nums) 16 | let addRecurse = (...nums) =>{ 17 | if(nums.length === 1){ 18 | return nums[0]; 19 | } 20 | else{ 21 | return nums[0] + addRecurse(...nums.slice(1)); 22 | } 23 | } 24 | addRecurse(3,1,2); 25 | 26 | 27 | 28 | //minRecurse(...nums) 29 | let minRecurse = (...nums) =>{ 30 | if (nums.length > 1){ 31 | nums[0] = Math.min(nums[0], nums[nums.length -1]); 32 | nums.pop(); 33 | return minRecurse(...nums); 34 | } 35 | else return nums[0]; 36 | } 37 | minRecurse(3,7,-3,1,0) 38 | 39 | 40 | 41 | //not(func) 42 | let not = (num) => num * -1 43 | not(2) 44 | -------------------------------------------------------------------------------- /Solutions/my-solutions-LJ.js: -------------------------------------------------------------------------------- 1 | //my solutions 2 | 3 | //identity solution 4 | const identity = (x) => x; 5 | console.log(identity(3)); 6 | 7 | //addb 8 | const addb = (a, b) => a + b; 9 | console.log(addb(3, 4)); 10 | 11 | //subb 12 | const subb = (a, b) => a - b; 13 | console.log(subb(3, 4)); 14 | 15 | //minb 16 | const minb = (a ,b) => { 17 | if(a > b){ 18 | return b; 19 | } else { 20 | return a; 21 | } 22 | } 23 | console.log(minb(3, 4)); 24 | /// 25 | -------------------------------------------------------------------------------- /Solutions/mySolution-mm.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zero-to-mastery/JS_Fun_Practice/dfd64fa5f66bbd6bb9a1d4b14c13416440866a89/Solutions/mySolution-mm.js -------------------------------------------------------------------------------- /Solutions/mySolutions-TH.js: -------------------------------------------------------------------------------- 1 | // identity(x) ⇒ any 2 | // Write a function identity that takes an argument and returns that argument 3 | const identity = (x) => x; 4 | console.log(identity(27)); 5 | 6 | // addb(a, b) ⇒ number 7 | // Write a binary function addb that takes two numbers and returns their sum 8 | const addb = (a, b) => a + b; 9 | console.log(addb(2, 5)); 10 | 11 | // subb(a, b) ⇒ number 12 | // Write a binary function subb that takes two numbers and returns their difference 13 | const subb = (a, b) => a - b; 14 | console.log(subb(5, 2)); 15 | 16 | // mulb(a, b) ⇒ number 17 | // Write a binary function mulb that takes two numbers and returns their product 18 | const mulb = (a, b) => a * b; 19 | console.log(mulb(3, 4)); 20 | 21 | // minb(a, b) ⇒ number 22 | // Write a binary function minb that takes two numbers and returns the smaller one 23 | const minb = (a, b) => { return a < b ? a : b; } 24 | console.log(minb(5, 2)); 25 | 26 | // maxb(a, b) ⇒ number 27 | // Write a binary function maxb that takes two numbers and returns the larger one 28 | const minb = (a, b) => { return a > b ? a : b; } 29 | console.log(minb(5, 12)); 30 | 31 | // add(...nums) ⇒ number 32 | // Write a function add that is generalized for any amount of arguments 33 | const add = (...nums) => { 34 | return nums.reduce( ( acc, i ) => { 35 | return acc + i; 36 | }, 0) 37 | }; 38 | console.log(add(1,4,3,5,1)); 39 | 40 | // sub(...nums) ⇒ number 41 | // Write a function sub that is generalized for any amount of arguments 42 | const sub = (...nums) => { 43 | return nums.reduce( ( acc, i ) => { 44 | return acc - i; 45 | }, 0) 46 | } 47 | console.log(sub(1,4,3,5,1)); 48 | 49 | // mul(...nums) ⇒ number 50 | // Write a function mul that is generalized for any amount of arguments 51 | const mul = (...nums) => { 52 | return nums.reduce( ( acc, i ) => { 53 | return acc * i 54 | }) 55 | } 56 | console.log(mul(1,4,3,5,1)); 57 | 58 | // min(...nums) ⇒ number 59 | // Write a function min that is generalized for any amount of arguments 60 | const min = (...nums) => { 61 | return nums.reduce( ( acc, i ) => { 62 | return acc < i ? acc : acc = i; 63 | }, nums[0]) 64 | } 65 | console.log(min(4, 3, -5, 1, 10, -2)); 66 | 67 | // max(...nums) ⇒ number 68 | // Write a function max that is generalized for any amount of arguments; 69 | const max = (...nums) => { 70 | return nums.reduce( ( acc, i ) => { 71 | return acc > i ? acc : acc = i; 72 | }, nums[0]) 73 | } 74 | console.log(max(4, 3, -5, 1, 10, -2)); 75 | 76 | // addRecurse(...nums) ⇒ number 77 | // Write a function addRecurse that is the generalized add function but uses recursion 78 | const addRecurse = (nums) => { return nums.length === 1 ? nums[0] : nums.pop() + addRecurse(nums); }; 79 | console.log(addRecurse([1, 2, 3, 4])); // Can't figure out how to do it without passing an Array 80 | 81 | // mulRecurse(...nums) ⇒ number 82 | // Write a function mulRecurse that is the generalized mul function but uses recursion 83 | const mulRecurse = (nums) => { return nums.length === 1 ? nums[0] : nums.pop() * mulRecurse(nums); }; 84 | console.log(mulRecurse([1, 2, 3, 4])); // Can't figure out how to do it without passing an Array -------------------------------------------------------------------------------- /Solutions/mySolutions-oakj.js: -------------------------------------------------------------------------------- 1 | // write a function identity that takes an argument and returns that argument 2 | 3 | const identity = (arg) => arg; -------------------------------------------------------------------------------- /Solutions/mySolutions.js: -------------------------------------------------------------------------------- 1 | // 1. Write a function identity that takes an argument and returns that argument 2 | const identity = (x) => x; 3 | console.log(identity('Hello there!')); 4 | 5 | // 2. Write a binary function addb that takes two numbers and returns their sum 6 | const addb = (x, y) => x + y; 7 | console.log(addb(3, 7)); 8 | 9 | // 3. Write a binary function subb that takes two numbers and returns their difference 10 | const subb = (x, y) => x - y; 11 | console.log(subb(7, 2)); 12 | 13 | // 4. Write a binary function mulb that takes two numbers and returns their product 14 | const mulb = (x, y) => x * y; 15 | console.log(mulb(2, 5)); 16 | 17 | // 5. Write a binary function minb that takes two numbers and returns the smaller one 18 | const minb = (x, y) => x < y ? x : y; 19 | console.log(minb(7, 3)); 20 | 21 | // 6. Write a binary function maxb that takes two numbers and returns the larger one 22 | const maxb = (x, y) => x > y ? x : y; 23 | console.log(maxb(7, 3)); 24 | 25 | // 7. Write a function add that is generalized for any amount of arguments 26 | function add() { 27 | let x = 0; 28 | let i = 0; 29 | 30 | for (i ; i < arguments.length; i++) { 31 | x += arguments[i]; 32 | } 33 | return x; 34 | } 35 | console.log(add(1, 2, 4)); 36 | 37 | // 8. Write a function sub that is generalized for any amount of arguments 38 | function sub() { 39 | let i = 1; 40 | let x = arguments[0]; 41 | 42 | for (i ; i < arguments.length; i++) { 43 | x -= arguments[i]; 44 | } 45 | return x; 46 | } 47 | console.log(sub(1, 2, 4)); 48 | 49 | // 9. Write a function mul that is generalized for any amount of arguments 50 | function mul() { 51 | let x = arguments[0]; 52 | 53 | for (let i = 1; i < arguments.length; i++) { 54 | x *= arguments[i]; 55 | } 56 | return x; 57 | } 58 | console.log(mul(1, 2, 4)); 59 | 60 | // 10. Write a function min that is generalized for any amount of arguments 61 | function min() { 62 | let min = arguments[0]; 63 | 64 | for (let i = 1; i < arguments.length; i++) { 65 | min > arguments[i]? min = arguments[i]: min ; 66 | } 67 | return min; 68 | } 69 | console.log(min(1, 2, 4)); 70 | 71 | // 11. Write a function max that is generalized for any amount of arguments 72 | function max() { 73 | let max = arguments[0]; 74 | 75 | for (let i = 1; i < arguments.length; i++) { 76 | max < arguments[i]? max = arguments[i]: max ; 77 | } 78 | return max; 79 | } 80 | console.log(max(1, 2, 4)); -------------------------------------------------------------------------------- /Solutions/mySolutionsAU.js: -------------------------------------------------------------------------------- 1 | //to add two values 2 | const addb = (a,b) => a+b; 3 | console.log(addb(a,b)); 4 | 5 | //to subtract two values 6 | const subb = (a,b) => a-b; 7 | console.log(subb(a,b)); 8 | 9 | //to multiply two values 10 | const mulb = (a,b) => a*b; 11 | console.log(mulb(a,b)); 12 | 13 | //to find minimum of two values 14 | const minb = (a, b) => (a (a>b)?a:b; 19 | console.log(maxb(a,b)); -------------------------------------------------------------------------------- /Solutions/my_solution_itsnou.js: -------------------------------------------------------------------------------- 1 | //1) 2 | const identify=x=>x 3 | 4 | //2) 5 | 6 | const addb= (a,b) => a+b 7 | 8 | //3) 9 | 10 | const subb= (a,b) => a-b 11 | 12 | //4) 13 | 14 | const mulb= (a,b) => a*b 15 | 16 | //5) 17 | 18 | const minb= (a,b) =>{ 19 | if(a>b){ 20 | return b 21 | }else return a 22 | } 23 | // other solution 24 | const minb= (a,b) => a a>b ? a : b 29 | 30 | //other solution 31 | 32 | function maxb(a,b){ 33 | if(a>b){ 34 | return a 35 | }else return b 36 | } 37 | 38 | //7) 39 | 40 | const add= (...nums)=> nums.reduce((num, nums)=> num+nums) 41 | 42 | //8) 43 | 44 | const sub= (...varios)=> varios.reduce((num,varios)=>num-varios) 45 | 46 | //9) 47 | 48 | const mul = (...nums)=> nums.reduce((num,nums)=> num*nums) 49 | 50 | //10) 51 | 52 | function min(...nums){ 53 | let menor=nums[0] 54 | for(let i=1;imayor){ 68 | mayor=nums[i] 69 | } 70 | }return mayor 71 | } 72 | 73 | //12) Write a function addRecurse that is the generalized add function but uses recursion 74 | 75 | function addReduce(...nums){ 76 | let sum=0 77 | for(let i=0;imayor){ 111 | mayor=nums[i] 112 | }i++ 113 | }return mayor 114 | } 115 | 116 | //16) Write a function not that takes a function and returns the negation of its result 117 | 118 | const isOdd= (num)=>{ 119 | return (num%2!=0?false:true) 120 | } 121 | 122 | const not= (func)=>{ 123 | return !func 124 | } 125 | 126 | console.log(not(isOdd(2))) 127 | console.log('--------------') 128 | 129 | -------------------------------------------------------------------------------- /Solutions/my_solutions.js: -------------------------------------------------------------------------------- 1 | 2 | /// Write a function identity that takes an argument and returns that argument 3 | 4 | const identity = (x) => x; 5 | console.log(identity("Hello World!")); 6 | 7 | // Write a binary function addb that takes two numbers and returns their sum 8 | 9 | const addb = (a, b) => a+b; 10 | console.log(addb(2,3)); 11 | 12 | // Write a binary function subb that takes two numbers and returns their difference 13 | 14 | const subb = (a,b) => a-b; 15 | console.log(5,3); 16 | 17 | // Write a binary function mulb that takes two numbers and returns their product 18 | 19 | const mulb = (a, b) => a*b; 20 | console.log(mulb(5,3)); 21 | 22 | // Write a binary function minb that takes two numbers and returns the smaller one 23 | 24 | const minb = (a,b) => a < b ? a : b; 25 | console.log(minb(5,3)); 26 | 27 | // Write a binary function maxb that takes two numbers and returns the larger one 28 | 29 | const minb = (a,b) => a > b ? a : b; 30 | console.log(minb(5,3)); 31 | 32 | // Write a function add that is generalized for any amount of arguments 33 | 34 | const add = (...nums) => nums.reduce((a,b) => a+b); 35 | console.log(add(2,3,4)); 36 | 37 | // Write a function sub that is generalized for any amount of arguments 38 | 39 | const sub = (...nums) => nums.reduce((a,b) => a-b); 40 | console.log(sub(2,3,4)); 41 | 42 | // Write a function mul that is generalized for any amount of arguments 43 | 44 | const mul = (...nums) => nums.reduce((a,b) => a*b); 45 | console.log(mul(2,3,4)); 46 | 47 | // Write a function min that is generalized for any amount of arguments 48 | 49 | const min = (...nums) => nums.reduce((a,b) => a < b ? a:b); 50 | console.log(min(2,3,4)); 51 | 52 | // Write a function max that is generalized for any amount of arguments 53 | 54 | const max = (...nums) => nums.reduce((a, b) => a > b ? a:b); 55 | console.log(max(2,35,43)); 56 | 57 | // Write a function addRecurse that is the generalized add function but uses recursion 58 | 59 | const addRecurse = (...nums) => { 60 | if(nums.length < 1) 61 | return 0 62 | return nums[0] + addRecurse(...nums.slice(1)) 63 | } 64 | console.log(addRecurse(1,-2,3,4)); 65 | 66 | // Write a function mulRecurse that is the generalized mul function but uses recursion 67 | 68 | const mulRecurse = (...nums) => { 69 | if(nums.length < 1) 70 | return 1 71 | return nums[0] * mulRecurse(...nums.slice(1)) 72 | } 73 | console.log(mulRecurse(1,-2,3,4)); 74 | 75 | // Write a function minRecurse that is the generalized min function but uses recursion 76 | 77 | const minRecurse = (...nums) => { 78 | if(nums.length < 1) 79 | return 1 80 | return nums[0] < minRecurse(...nums.slice(1)) ? nums[0]:minRecurse(...nums.slice(1)) 81 | } 82 | console.log(minRecurse(1,33,2,3,-1)); 83 | 84 | // Write a function maxRecurse that is the generalized max function but uses recursion 85 | 86 | const maxRecurse = (...nums) => { 87 | if(nums.length < 1) 88 | return 1 89 | return nums[0] < maxRecurse(...nums.slice(1)) ? nums[0]:maxRecurse(...nums.slice(1)) 90 | } 91 | console.log(maxRecurse(1,33,2,3,-1)); 92 | 93 | // Write a function not that takes a function and returns the negation of its result 94 | 95 | const not = (fun) => { 96 | return function (...args) { 97 | return !fun(...args); 98 | }; 99 | } 100 | const isOdd = (a) => a % 2 !== 0; 101 | const isEven = not(isOdd); 102 | console.log(isEven(7)); -------------------------------------------------------------------------------- /Solutions/nataliaSolution.js: -------------------------------------------------------------------------------- 1 | const identity = (x) => x; 2 | const addb = (a,b) => a + b; 3 | const subb = (a,b) => a - b; 4 | const mulb = (a,b) => a * b; 5 | const minb = (a, b) => a < b ? a : b; 6 | const maxb = (a, b) => a > b ? a : b; 7 | const add = (...nums) => { 8 | let total = 0; 9 | for(let i in nums){ 10 | x = x + nums[i] 11 | } 12 | return x; 13 | }; 14 | const sub = (...nums) => { 15 | let x = 0; 16 | for(let i in nums){ 17 | x = x - nums[i] 18 | } 19 | return x; 20 | }; 21 | 22 | const mul = (...nums) => { 23 | let x = 0; 24 | for(let i in nums){ 25 | x = x * nums[i] 26 | } 27 | return x; 28 | }; 29 | 30 | const min = (...nums) => { 31 | let x = nums[0]; 32 | for(let i in nums){ 33 | nums[i] < x ? x = nums[i] : x = x; 34 | } 35 | return x; 36 | }; 37 | 38 | const max = (...nums) => { 39 | let x = nums[0]; 40 | for(let i in nums){ 41 | nums[i] > x ? x = nums[i] : x = x; 42 | } 43 | return x; 44 | }; 45 | 46 | const addRecurse = (...nums) => { 47 | if (nums.length === 1) { 48 | return nums[0]; 49 | } else { 50 | return nums.shift() + addRecurse(...nums); 51 | } 52 | }; 53 | 54 | const mulRecurse = (...nums) => { 55 | if (nums.length === 1) { 56 | return nums[0]; 57 | } else { 58 | return nums.shift() * mulRecurse(...nums); 59 | } 60 | }; 61 | 62 | // not finished yet 63 | 64 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, }; -------------------------------------------------------------------------------- /Solutions/princeo1.js: -------------------------------------------------------------------------------- 1 | let a=0 2 | for(int i=0;i x; 2 | 3 | const addition = (a,b) => a+b; 4 | 5 | const subtraction = (a,b) => a-b; 6 | 7 | const mul = (a,b) => a*b; 8 | 9 | const mini = (a,b) => a > b ? b : a; 10 | 11 | const maxi = (a,b) => a > b ? a : b; 12 | 13 | 14 | -------------------------------------------------------------------------------- /Solutions/pyramid.js: -------------------------------------------------------------------------------- 1 | // This is a function that accepts a positive number N. 2 | // It console logs a pyramid shape 3 | // with N levels using the # character with no spaces on both the left *and* right hand sides 4 | // These are some examples 5 | // pyramid(1) 6 | // '#' 7 | // pyramid(2) 8 | // ' # ' 9 | // '###' 10 | // pyramid(3) 11 | // ' # ' 12 | // ' ### ' 13 | // '#####' 14 | 15 | function pyramid(n, row = 0, level = '') { 16 | if (row === n) { 17 | return; 18 | } 19 | 20 | if (level.length === 2 * n - 1) { 21 | console.log(level); 22 | return pyramid(n, row + 1); 23 | } 24 | 25 | const midpoint = Math.floor((2 * n - 1) / 2); 26 | let add; 27 | if (midpoint - row <= level.length && midpoint + row >= level.length) { 28 | add = '#'; 29 | } else { 30 | add = ' '; 31 | } 32 | pyramid(n, row, level + add); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Solutions/rafia-z-solutions: -------------------------------------------------------------------------------- 1 | //Write a function identity that takes an argument and returns that argument 2 | 3 | const identity = (b) => { 4 | return b; 5 | } 6 | 7 | 8 | -------------------------------------------------------------------------------- /Solutions/ranran2121_solutions.js: -------------------------------------------------------------------------------- 1 | // identity(x) ⇒ any 2 | // Write a function identity that takes an argument and returns that argument 3 | function identity(x) { 4 | return x; 5 | } 6 | 7 | //addb(a, b) ⇒ number 8 | //Write a binary function addb that takes two numbers and returns their sum 9 | function addb(a, b) { 10 | return a + b; 11 | } 12 | 13 | //subb(a, b) ⇒ number 14 | //Write a binary function subb that takes two numbers and returns their difference 15 | function subb(a, b) { 16 | return a - b; 17 | } 18 | //mulb(a, b) ⇒ number 19 | //Write a binary function mulb that takes two numbers and returns their product 20 | function mulb(a, b) { 21 | return a * b; 22 | } 23 | //minb(a, b) ⇒ number 24 | //Write a binary function minb that takes two numbers and returns the smaller one 25 | function minb(a, b) { 26 | if (a < b) { 27 | return a; 28 | } else { 29 | return b; 30 | } 31 | } 32 | //maxb(a, b) ⇒ number 33 | //Write a binary function maxb that takes two numbers and returns the larger one 34 | function maxb(a, b) { 35 | if (a > b) { 36 | return a; 37 | } else { 38 | return b; 39 | } 40 | } 41 | //add(...nums) ⇒ number 42 | //Write a function add that is generalized for any amount of arguments 43 | function add(...nums) { 44 | let sum = nums[0]; 45 | for (let i = 1; i < nums.length; i++) { 46 | sum += nums[i]; 47 | } 48 | return sum; 49 | } 50 | //sub(...nums) ⇒ number 51 | //Write a function sub that is generalized for any amount of arguments 52 | function sub(...nums) { 53 | let sub = nums[0]; 54 | for (let i = 1; i < nums.length; i++) { 55 | sub -= nums[i]; 56 | } 57 | return sub; 58 | } 59 | 60 | // Write a function identityf that takes an argument and returns a function that returns that argument 61 | function identityf(x) { 62 | return identity(x); 63 | } 64 | 65 | // Write a function addf that adds from two invocations 66 | function addf(a) { 67 | return (b) => { 68 | return add(a, b); 69 | }; 70 | } 71 | 72 | // Write a function liftf that takes a binary function, and makes it callable with two invocations 73 | function liftf(fn) { 74 | return (a) => { 75 | return (b) => { 76 | return fn(a, b); 77 | }; 78 | }; 79 | } 80 | 81 | module.exports = { 82 | identity, 83 | addb, 84 | subb, 85 | mulb, 86 | minb, 87 | maxb, 88 | add, 89 | sub, 90 | identityf, 91 | addf, 92 | liftf, 93 | }; 94 | -------------------------------------------------------------------------------- /Solutions/raza_solutions.js: -------------------------------------------------------------------------------- 1 | 2 | // identity(x) ⇒ any 3 | // Write a function identity that takes an argument and returns that argument 4 | const identity = (x) => x; 5 | console.log('Hey there, Delilah'); 6 | 7 | //addb(a, b) ⇒ number 8 | //Write a binary function addb that takes two numbers and returns their sum 9 | const addb = (x, y) => (x + y); 10 | console.log(`What's it like in New York city?`); 11 | 12 | 13 | //subb(a, b) ⇒ number 14 | //Write a binary function subb that takes two numbers and returns their difference 15 | const subb = (x, y) => ( x - y); 16 | console.log(`I'm a thousand miles away`); 17 | 18 | //mulb(a, b) ⇒ number 19 | //Write a binary function mulb that takes two numbers and returns their product 20 | 21 | const mulb = (x, y) => (x * y); 22 | console.log(`But, girl, tonight you look so pretty`) 23 | 24 | //minb(a, b) ⇒ number 25 | //Write a binary function minb that takes two numbers and returns the smaller one 26 | const minb = (x, y) => (x < y ? x : y); 27 | 28 | console.log(`Yes, you do`); 29 | 30 | 31 | //maxb(a, b) ⇒ number 32 | //Write a binary function maxb that takes two numbers and returns the larger one 33 | const maxb = (x, y) => { 34 | return x > y ? x : y; 35 | } 36 | console.log(`Time square can't shine as bright as you`); 37 | 38 | 39 | //add(...nums) ⇒ number 40 | //Write a function add that is generalized for any amount of arguments 41 | const add = (...nums) => { 42 | let add = 0; 43 | for (let i = 0; i < nums.length; i++) { 44 | add += nums[i]; 45 | } 46 | return add; 47 | }; 48 | console.log(`I swear, it's true`); 49 | 50 | //sub(...nums) ⇒ number 51 | //Write a function sub that is generalized for any amount of arguments 52 | const sub = (...nums) => nums.reduce((acc, cur) => acc - cur); 53 | 54 | console.log(sub(1, 2, 4)); 55 | 56 | module.exports = { 57 | identity, 58 | addb, 59 | subb, 60 | mulb, 61 | minb, 62 | maxb, 63 | add, 64 | sub 65 | }; -------------------------------------------------------------------------------- /Solutions/salih_solution.js: -------------------------------------------------------------------------------- 1 | const identity=(arg)=>arg 2 | 3 | const addb=(a,b)=>a+b 4 | 5 | const subb=(a,b)=>a-b 6 | 7 | const mulb=(a,b)=>a*b 8 | 9 | const minb=(a,b)=>aa>b ? a:b 12 | 13 | const add = (...nums)=>{ 14 | return nums.reduce((total,amount)=>total + amount) 15 | } 16 | 17 | const sub = (...nums)=>{ 18 | return nums.reduce((total,amount)=>total - amount) 19 | } 20 | 21 | const mul = (...nums)=>{ 22 | return nums.reduce((total,amount)=>total * amount) 23 | } 24 | 25 | const min = (...nums)=>{ 26 | return nums.reduce((total,amount)=>total < amount ? total:amount) 27 | } 28 | 29 | 30 | //for now i did this i i will contribute everyday 31 | 32 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul,min}; 33 | 34 | -------------------------------------------------------------------------------- /Solutions/samkcrespo_solutions.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | const identity = x => x; 3 | console.log(identity(10)); 4 | // Write a binary function addb that takes two numbers and returns their sum 5 | const addb = (a,b) => a + b; 6 | console.log(addb(5,5)); 7 | // Write a binary function subb that takes two numbers and returns their difference 8 | const subb = (a,b) => a - b; 9 | console.log(subb(15,5)); 10 | // Write a binary function mulb that takes two numbers and returns their product 11 | const mulb = (a,b) => a * b; 12 | console.log(mulb(5,2)); 13 | // Write a binary function minb that takes two numbers and returns the smaller one 14 | const minb = (a,b) => a a>b ? a : b; 18 | console.log(maxb(10,3)); 19 | // Write a function add that is generalized for any amount of arguments 20 | 21 | const add = (...nums) => nums.reduce((acc,currentVal) => acc += currentVal); 22 | 23 | module.exports = { 24 | identity, 25 | addb, 26 | subb, 27 | mulb, 28 | minb, 29 | maxb, 30 | add, 31 | sub, 32 | mul, 33 | min, 34 | max, 35 | addRecurse, 36 | mulRecurse, 37 | minRecurse, 38 | maxRecurse, 39 | not, 40 | acc, 41 | accPartial, 42 | accRecurse, 43 | fill, 44 | fillRecurse, 45 | set, 46 | identityf, 47 | addf, 48 | liftf, 49 | pure, 50 | curryb, 51 | curry, 52 | inc, 53 | twiceUnary, 54 | doubl, 55 | square, 56 | twice, 57 | reverseb, 58 | reverse, 59 | composeuTwo, 60 | composeu, 61 | composeb, 62 | composeTwo, 63 | compose, 64 | limitb, 65 | limit, 66 | genFrom, 67 | genTo, 68 | genFromTo, 69 | elementGen, 70 | element, 71 | collect, 72 | filter, 73 | filterTail, 74 | concatTwo, 75 | concat, 76 | concatTail, 77 | gensymf, 78 | gensymff, 79 | fibonaccif, 80 | counter, 81 | revocableb, 82 | revocable, 83 | extract, 84 | m, 85 | addmTwo, 86 | addm, 87 | liftmbM, 88 | liftmb, 89 | liftm, 90 | exp, 91 | expn, 92 | addg, 93 | liftg, 94 | arrayg, 95 | continuizeu, 96 | continuize, 97 | vector, 98 | exploitVector, 99 | vectorSafe, 100 | pubsub, 101 | mapRecurse, 102 | filterRecurse, 103 | }; -------------------------------------------------------------------------------- /Solutions/saud06_solutions.js: -------------------------------------------------------------------------------- 1 | const identity = ele => ele; 2 | 3 | const addb = (a,b) => a+b; 4 | 5 | const subb = (a,b) => a-b; 6 | 7 | const mulb = (a,b) => a*b; 8 | 9 | const minb = (a,b) => a a>b ? a : b; 12 | 13 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, }; 14 | -------------------------------------------------------------------------------- /Solutions/schmeb0704_solution.js: -------------------------------------------------------------------------------- 1 | // Write a function twiceUnary that takes a binary function and returns a unary function that passes its argument to the binary function twice 2 | function twiceUnary(binaryFunc, n){ 3 | function unaryFunc(input){ 4 | return binaryFunc(input, input) 5 | } 6 | 7 | return unaryFunc(n) 8 | } 9 | 10 | // Use the function twiceUnary to create the doubl function 11 | 12 | function doubl(n){ 13 | const times2 = (num1, num2) => num1 + num2 14 | 15 | return twiceUnary(times2, n) 16 | 17 | } 18 | 19 | // Use the function twiceUnary to create the square function 20 | 21 | function square(n){ 22 | const selfMult = (num1, num2) => num1 * num2 23 | 24 | return twiceUnary(selfMult, n) 25 | 26 | } 27 | 28 | module.exports = { 29 | // identity, 30 | // addb, 31 | // subb, 32 | // mulb, 33 | // minb, 34 | // maxb, 35 | // add, 36 | // sub, 37 | // mul, 38 | // min, 39 | // max, 40 | // addRecurse, 41 | // mulRecurse, 42 | // minRecurse, 43 | // maxRecurse, 44 | // not, 45 | // acc, 46 | // accPartial, 47 | // accRecurse, 48 | // fill, 49 | // fillRecurse, 50 | // set, 51 | // identityf, 52 | // addf, 53 | // liftf, 54 | // pure, 55 | // curryb, 56 | // curry, 57 | // inc, 58 | twiceUnary, 59 | doubl, 60 | square, 61 | // twice, 62 | // reverseb, 63 | // reverse, 64 | // composeuTwo, 65 | // composeu, 66 | // composeb, 67 | // composeTwo, 68 | // compose, 69 | // limitb, 70 | // limit, 71 | // genFrom, 72 | // genTo, 73 | // genFromTo, 74 | // elementGen, 75 | // element, 76 | // collect, 77 | // filter, 78 | // filterTail, 79 | // concatTwo, 80 | // concat, 81 | // concatTail, 82 | // gensymf, 83 | // gensymff, 84 | // fibonaccif, 85 | // counter, 86 | // revocableb, 87 | // revocable, 88 | // extract, 89 | // m, 90 | // addmTwo, 91 | // addm, 92 | // liftmbM, 93 | // liftmb, 94 | // liftm, 95 | // exp, 96 | // expn, 97 | // addg, 98 | // liftg, 99 | // arrayg, 100 | // continuizeu, 101 | // continuize, 102 | // vector, 103 | // exploitVector, 104 | // vectorSafe, 105 | // pubsub, 106 | // mapRecurse, 107 | // filterRecurse, 108 | }; -------------------------------------------------------------------------------- /Solutions/solution_D.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | // ES5 3 | const identity = function(argument) { 4 | return argument; 5 | } 6 | // or ES6 (where you don't need the function keyword, the return keyword, and the curly brackets.): 7 | const identity = (x) => x; 8 | 9 | //Write a binary function addb that takes two numbers and returns their sum 10 | // ES5 11 | const addb = function (a, b) { 12 | return (a + b); 13 | } 14 | //or ES6 15 | const addb = (a, b) => a + b; 16 | 17 | // Write a binary function subb that takes two numbers and returns their difference 18 | // ES5 19 | const subb = function (a, b) { 20 | return a - b; 21 | } 22 | // ES6 23 | const subb = (a, b) => a - b; 24 | 25 | // Write a binary function mulb that takes two numbers and returns their product 26 | // ES5 27 | const mulb = function(a, b) { 28 | return a * b; 29 | } 30 | // ES6 31 | const mulb = (a, b) => a * b; 32 | 33 | // Write a binary function minb that takes two numbers and returns the smaller one 34 | const minb = (a, b) => a < b ? a : b; 35 | 36 | // Write a binary function maxb that takes two numbers and returns the larger one 37 | const maxb = (a, b) => a > b ? a : b; 38 | 39 | // Write a function add that is generalized for any amount of arguments 40 | const add = (...nums) => nums.reduce((a, b)=>a+b) 41 | 42 | // Write a function sub that is generalized for any amount of arguments 43 | const sub = (...nums) => nums.reduce((a, b)=>a-b) 44 | 45 | //Write a function mul that is generalized for any amount of arguments 46 | const mul = (...nums) => nums.reduce((a, b)=>a*b , 1) 47 | 48 | // Write a function min that is generalized for any amount of arguments 49 | const min = (...nums) => nums.reduce((a, b)=> Math.min(a, b)) 50 | 51 | // Write a function max that is generalized for any amount of arguments 52 | const max = (...nums) => nums.reduce((a, b)=> Math.max(a, b)) 53 | 54 | // Write a function addRecurse that is the generalized add function but uses recursion 55 | const addRecurse = (...nums) => { 56 | if (nums.length === 1) return nums[0] 57 | return nums.pop() + addRecurse(...nums); 58 | } 59 | 60 | // Write a function mulRecurse that is the generalized mul function but uses recursion 61 | const mulRecurse = (...nums) => { 62 | if (nums.length === 1) return nums[0] 63 | return nums.pop() * mulRecurse(...nums); 64 | } 65 | 66 | // Write a function minRecurse that is the generalized min function but uses recursion 67 | const minRecurse = (...nums) => { 68 | if (nums.length === 1) return nums[0] 69 | let secondNum = minRecurse(...nums.slice(1)) 70 | if (nums[0] < secondNum) return nums[0] 71 | return secondNum 72 | } 73 | 74 | // Write a function maxRecurse that is the generalized max function but uses recursion 75 | const maxRecurse = (...nums) => { 76 | if (nums.length === 1) return nums[0] 77 | let secondNum = maxRecurse(...nums.slice(1)) 78 | if (nums[0] > secondNum) return nums[0] 79 | return secondNum 80 | } 81 | 82 | // Write a function not that takes a function and returns the negation of its result 83 | const not = func => (...args) => 84 | !Boolean(func(...args)) 85 | 86 | //Write a function acc that takes a function and an initial value and returns a function that runs the initial function on each argument, accumulating the result 87 | const acc = (func, initial) => (...args) => { 88 | let final = initial; 89 | for (let i of args) { 90 | final = func(final, i); 91 | } 92 | return final; 93 | } 94 | // Write a function accPartial that takes in a function, a start index, and an end index, and returns a function that accumulates a subset of its arguments by applying the given function to all elements between start and end. 95 | const accPartial = (func, start, end) => (...args) => { 96 | const array = args.slice(start, end); 97 | let final = array[0]; 98 | for (let i of array.slice(1)) { 99 | final = func(final, i); 100 | } 101 | args.splice(start, end - start); 102 | args.splice(start, 0, final) 103 | return args 104 | } 105 | 106 | // Write a function accRecurse that does what acc does but uses recursion 107 | const accRecurse = (func, initial) => (...args) => { 108 | if (args.length === 1) { 109 | return func(args[0], initial); 110 | } 111 | return func(accRecurse(func, initial)(...args.slice(1)), args[0]); 112 | } 113 | 114 | const fill = (num) => { 115 | let arr = []; 116 | for(let i=0; i { 121 | if(arr.length === num){ 122 | return arr 123 | }else{ 124 | arr.push(num) 125 | return fillRecurse(num, arr) 126 | } 127 | } 128 | 129 | const set = (...args) => args.filter((arg, index) => args.indexOf(arg) === index); 130 | 131 | const identityf = arg => () => arg 132 | 133 | const addf = a => b => a + b; 134 | 135 | const liftf = fun => a => b => fun(a, b) 136 | 137 | const pure = (x, y) => { 138 | const impure = (x) => { 139 | y++; 140 | z = x * y; 141 | } 142 | impure(x); 143 | return [y, z]; 144 | } 145 | 146 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, /*curryb, curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, */ }; -------------------------------------------------------------------------------- /Solutions/solutiongilboa48.js: -------------------------------------------------------------------------------- 1 | const identity = (x) => x; 2 | const addb = (a,b) => a+b; 3 | const subb = (a,b) => a-b; 4 | const mulb = (a,b) => a*b; 5 | const minb = (a,b) => { 6 | if (a { 16 | if (a>b) { 17 | return a; 18 | } 19 | if (b>a) { 20 | return b; 21 | } else { 22 | console.log (`${a} = ${b} no maximum number`); 23 | } 24 | } 25 | //Write a function add that is generalized for any amount of arguments 26 | const add = (...numbers) => { 27 | return numbers.reduce((total,num) => total+num); 28 | } 29 | //Write a function sub that is generalized for any amount of arguments 30 | const sub = (...numbers) => { 31 | return numbers.reduce((total,num) => total-num); 32 | } 33 | //Write a function mul that is generalized for any amount of arguments 34 | const mul = (...numbers) => { 35 | return numbers.reduce((total,num) => total*num); 36 | } 37 | //Write a function min that is generalized for any amount of arguments 38 | const min = (...numbers) => { 39 | let x = numbers[0]; 40 | for (i=1; i numbers[i]) { 42 | x=numbers[i]; 43 | } 44 | } 45 | return x; 46 | } 47 | //Write a function max that is generalized for any amount of arguments 48 | const max = (...numbers) => { 49 | let x = numbers[0]; 50 | for (i=1; i { 60 | x=x+numbers[0]; 61 | numbers.shift(); 62 | if (numbers.length > 0){ 63 | addRecurse(...numbers); 64 | } 65 | return x; 66 | } 67 | //Write a function mulRecurse that is the generalized mul function but uses recursion 68 | let y=1; 69 | const mulRecurse = (...numbers) => { 70 | y=y*numbers[0]; 71 | numbers.shift(); 72 | if (numbers.length > 0){ 73 | mulRecurse(...numbers); 74 | } 75 | return y; 76 | } 77 | //Write a function not that takes a function and returns the negation of its result 78 | const not = func => func?false:true; 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /Solutions/solutionsSoldin: -------------------------------------------------------------------------------- 1 | //Write a function identity that takes an argument and returns that argument 2 | 3 | const identity = (x) => x; 4 | 5 | //Write a binary function addb that takes two numbers and returns their sum 6 | 7 | const addb = (a, b) => a+b; 8 | 9 | //Write a binary function subb that takes two numbers and returns their difference 10 | 11 | const subb = (a, b) => a-b; 12 | 13 | //Write a binary function mulb that takes two numbers and returns their product 14 | 15 | const mulb = (a, b) => a*b; 16 | 17 | -------------------------------------------------------------------------------- /Solutions/some-solutions.js: -------------------------------------------------------------------------------- 1 | //Write a function identity that takes an argument and returns that argument 2 | 3 | const identity = (a) => a; 4 | identity(5); 5 | 6 | //Write a binary function addb that takes two numbers and returns their sum 7 | const addb = (a, b)=> a + b; 8 | console.log(addb(5,4)); 9 | 10 | //Write a binary function subb that takes two numbers and returns their difference 11 | const subb = (a, b)=> a - b; 12 | console.log(subb(5,4)); 13 | 14 | //Write a binary function mulb that takes two numbers and returns their product 15 | const mulb = (a, b)=> a * b; 16 | console.log(mulb(5,4)); 17 | 18 | //Write a binary function minb that takes two numbers and returns the smaller one 19 | const minb = (a, b) =>{ 20 | if (a < b){ 21 | return a; 22 | } 23 | } 24 | console.log(minb(3,8)); 25 | 26 | //Write a binary function maxb that takes two numbers and returns the larger one 27 | 28 | const maxb = (a, b) =>{ 29 | if (a < b){ 30 | return a; 31 | } 32 | } 33 | console.log(maxb(3,8)); 34 | 35 | //Write a function add that is generalized for any amount of arguments 36 | 37 | const add = (...nums) => nums.reduce((acc, nums) => { 38 | const sum = acc + nums; 39 | return sum; 40 | }, 0) 41 | console.log(add(9,6,3)); 42 | -------------------------------------------------------------------------------- /Solutions/sudwiptokm__solutions.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | const identity = x => x 3 | 4 | // Write a binary function addb that takes two numbers and returns their sum 5 | const addb = (a,b) => a+b 6 | 7 | // Write a binary function subb that takes two numbers and returns their difference 8 | const subb = (a,b) => a-b 9 | 10 | // Write a binary function mulb that takes two numbers and returns their product 11 | const mulb = (a,b) => a*b 12 | 13 | // Write a binary function minb that takes two numbers and returns the smaller one 14 | const minb = (a,b) => a < b ? a : b 15 | 16 | // Write a binary function maxb that takes two numbers and returns the larger one 17 | const maxb = (a,b) => a < b ? b : a 18 | 19 | // Write a function add that is generalized for any amount of arguments 20 | const add = (...nums) => nums.reduce((a,b)=> a+b) 21 | 22 | // Write a function sub that is generalized for any amount of arguments 23 | const sub = (...nums) => nums.reduce((a,b)=> a-b) 24 | 25 | // Write a function mul that is generalized for any amount of arguments 26 | const mul = (...nums) => nums.reduce((a,b) => a*b) 27 | 28 | // Write a function min that is generalized for any amount of arguments 29 | const min = (...nums) => nums.reduce((a,b) => Math.min(a,b)) 30 | 31 | // Write a function max that is generalized for any amount of arguments 32 | const max = (...nums) => nums.reduce((a,b) => Math.max(a,b)) 33 | 34 | // Write a function addRecurse that is the generalized add function but uses recursion 35 | const addRecurse = (...nums) => nums.reduce((a,b) => a + addRecurse(b)) 36 | 37 | // Write a function mulRecurse that is the generalized mul function but uses recursion 38 | const mulRecurse = (...nums) => nums.reduce((a,b) => a * mulRecurse(b)) 39 | 40 | // Write a function minRecurse that is the generalized min function but uses recursion 41 | const minRecurse = (...nums) => nums.reduce((a,b) => Math.min(a,minRecurse(b))) 42 | 43 | // Write a function maxRecurse that is the generalized max function but uses recursion 44 | const maxRecurse = (...nums) => nums.reduce((a,b) => Math.max(a,maxRecurse(b))) 45 | 46 | // Write a function not that takes a function and returns the negation of its result 47 | const not = func => func?false:true 48 | 49 | // Write a function acc that takes a function and an initial value and returns a function that runs the initial function on each argument, accumulating the result 50 | 51 | const acc = (func, i) =>{ 52 | const temp = (...nums) => { 53 | return nums.reduce((acc,num) => func(acc,num),i) 54 | } 55 | return temp 56 | } 57 | 58 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, compose, limitb, limit, genFrom, genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, concat, concatTail, gensymf, gensymff, fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, liftmb, liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, mapRecurse, filterRecurse, }; -------------------------------------------------------------------------------- /Solutions/tari-solution.js: -------------------------------------------------------------------------------- 1 | //Write a function to convert a binary number to a decimal number 2 | 3 | const binaryDec=(input)=> { 4 | return parseInt((input + '').replace(/[^01]/gi, ''), 2); 5 | } 6 | binaryDec('110011'); 7 | 8 | -------------------------------------------------------------------------------- /Solutions/tarunmankar_sol.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | const identity = (x) => x; 3 | 4 | //Write a binary function addb that takes two numbers and returns their sum 5 | const addb = (a, b) => a + b; 6 | 7 | // Write a binary function subb that takes two numbers and returns their difference 8 | const subb = (a, b) => a - b; 9 | 10 | // Write a binary function mulb that takes two numbers and returns their product 11 | const mulb = (a, b) => a * b; 12 | 13 | // Write a binary function minb that takes two numbers and returns the smaller one 14 | const minb = (a, b) => a < b ? a : b; 15 | 16 | // Write a binary function maxb that takes two numbers and returns the larger one 17 | const maxb = (a, b) => a > b ? a : b; 18 | 19 | // Write a function add that is generalized for any amount of arguments 20 | const add = (...nums) => nums.reduce((a, b)=>a+b) 21 | 22 | // Write a function sub that is generalized for any amount of arguments 23 | const sub = (...nums) => nums.reduce((a, b)=>a-b) 24 | 25 | //Write a function mul that is generalized for any amount of arguments 26 | const mul = (...nums) => nums.reduce((a, b)=>a*b , 1) 27 | 28 | // Write a function min that is generalized for any amount of arguments 29 | const min = (...nums) => nums.reduce((a, b)=> Math.min(a, b)) 30 | 31 | // Write a function max that is generalized for any amount of arguments 32 | const max = (...nums) => nums.reduce((a, b)=> Math.max(a, b)) 33 | 34 | // Write a function addRecurse that is the generalized add function but uses recursion 35 | const addRecurse = (...nums) => { 36 | if (nums.length === 1) return nums[0] 37 | return nums.pop() + addRecurse(...nums); 38 | } 39 | 40 | // Write a function mulRecurse that is the generalized mul function but uses recursion 41 | const mulRecurse = (...nums) => { 42 | if (nums.length === 1) return nums[0] 43 | return nums.pop() * mulRecurse(...nums); 44 | } 45 | 46 | // Write a function minRecurse that is the generalized min function but uses recursion 47 | const minRecurse = (...nums) => { 48 | if (nums.length === 1) return nums[0] 49 | let secondNum = minRecurse(...nums.slice(1)) 50 | if (nums[0] < secondNum) return nums[0] 51 | return secondNum 52 | } 53 | 54 | // Write a function maxRecurse that is the generalized max function but uses recursion 55 | const maxRecurse = (...nums) => { 56 | if (nums.length === 1) return nums[0] 57 | let secondNum = maxRecurse(...nums.slice(1)) 58 | if (nums[0] > secondNum) return nums[0] 59 | return secondNum 60 | } 61 | 62 | // Write a function not that takes a function and returns the negation of its result 63 | const not = func => (...args) => 64 | !Boolean(func(...args)) 65 | 66 | //Write a function acc that takes a function and an initial value and returns a function that runs the initial function on each argument, accumulating the result 67 | const acc = (func, initial) => (...args) => { 68 | let final = initial; 69 | for (let i of args) { 70 | final = func(final, i); 71 | } 72 | return final; 73 | } 74 | // Write a function accPartial that takes in a function, a start index, and an end index, and returns a function that accumulates a subset of its arguments by applying the given function to all elements between start and end. 75 | const accPartial = (func, start, end) => (...args) => { 76 | const array = args.slice(start, end); 77 | let final = array[0]; 78 | for (let i of array.slice(1)) { 79 | final = func(final, i); 80 | } 81 | args.splice(start, end - start); 82 | args.splice(start, 0, final) 83 | return args 84 | } 85 | 86 | // Write a function accRecurse that does what acc does but uses recursion 87 | const accRecurse = (func, initial) => (...args) => { 88 | if (args.length === 1) { 89 | return func(args[0], initial); 90 | } 91 | return func(accRecurse(func, initial)(...args.slice(1)), args[0]); 92 | } 93 | 94 | module.exports = { identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, maxRecurse, not, acc, accPartial, accRecurse }; 95 | -------------------------------------------------------------------------------- /Solutions/usergr_solution.js: -------------------------------------------------------------------------------- 1 | const identity = (x) => x; 2 | 3 | const addb = (a, b) => a + b; 4 | 5 | const subb = (a, b) => a - b ; 6 | 7 | const mulb = (a, b) => a * b; 8 | 9 | const minb = (a, b) => a > b ? b : a; 10 | 11 | const maxb = (x, y) => x > y ? x : y; 12 | 13 | function add() { 14 | let x = 0; 15 | let i = 0; 16 | 17 | for (i ; i < arguments.length; i++) { 18 | x += arguments[i]; 19 | } 20 | return x; 21 | } 22 | 23 | const sub = (...nums) => { 24 | return nums.reduce((total,amount)=>total - amount) 25 | } 26 | 27 | const mul = (...nums) => { 28 | return nums.reduce((total,amount)=>total * amount) 29 | } 30 | 31 | module.exports = { 32 | identity, 33 | addb, 34 | subb, 35 | mulb, 36 | minb, 37 | maxb, 38 | add, 39 | sub, 40 | mul 41 | }; -------------------------------------------------------------------------------- /Solutions/v1zei_solutions.js: -------------------------------------------------------------------------------- 1 | const identity = x => x 2 | 3 | const addb = (a, b) => a+b 4 | 5 | const subb = (a, b) => a-b 6 | 7 | const mulb = (a, b) => a*b 8 | 9 | const minb = (a, b) => a a>b ? a:b 12 | 13 | const add = (...nums) => nums.reduce((a, b) => a+b) 14 | 15 | const sub = (...nums) => nums.reduce((a, b) => a-b) 16 | 17 | const mul = (...nums) => nums.reduce((a, b) => a*b) 18 | 19 | const min = (...nums) => nums.reduce((a, b) => a nums.reduce((a, b) => a>b ? a:b) 22 | 23 | const addRecurse = (...nums) => { 24 | if(nums.length === 1) return nums[0] 25 | return nums.pop() + addRecurse(...nums) 26 | } 27 | 28 | const mulRecurse = (...nums) =>{ 29 | if(nums.length === 2) return nums[0]*nums[1] 30 | return nums.pop() * mulRecurse(...nums) 31 | } 32 | 33 | const minRecurse = (...nums) =>{ 34 | if(nums.length === 2) return Math.min(nums[0], nums[1]) 35 | return Math.min(nums.pop(), minRecurse(...nums)) 36 | } 37 | 38 | const maxRecurse = (...nums) =>{ 39 | if(nums.length === 2) return Math.max(nums[0], nums[1]) 40 | return Math.max(nums.pop(), maxRecurse(...nums)) 41 | } 42 | 43 | const not = func => (...nums) => !Boolean(func(...nums)) 44 | 45 | const acc = (func, start) => (...args) => args.reduce((acc, num)=> func(acc, num), start) 46 | 47 | const accPartial = (func, start, end) => (...nums) =>{ 48 | let arr = nums.slice(start, end).reduce((acc, num) => func(acc, num)) 49 | nums.splice(start, end-start, arr) 50 | return nums 51 | } 52 | 53 | const accRecurse = (func, startValue) => (...args) =>{ 54 | if(args.length === 1) return func(startValue, args[0]) 55 | return func(accRecurse(func, startValue)(...args.slice(1)), args[0]) 56 | } 57 | 58 | const fill = num => new Array(num).fill(num) 59 | 60 | const fillRecurse = (num, arr = []) =>{ 61 | if(num === arr.length) return arr 62 | return fill(num, arr.push(num)) 63 | } 64 | 65 | const set = (...args) => [...new Set(args)] 66 | 67 | const identityf = x => () => x 68 | 69 | const addf = a => b => a+b 70 | 71 | const liftf = func => a => b => func(a, b) 72 | 73 | const pure = (x, y) => [++y, y*x] 74 | // const pure = (x, y) =>{ 75 | // const impure = (x) => { 76 | // y++; 77 | // z = x*y; 78 | // } 79 | // impure(x) 80 | // return [y, z] 81 | // } 82 | 83 | const curryb = (func, value) => a => func(a, value) 84 | 85 | const curry = (func, ...args) => (...nums) => func(...args, ...nums) 86 | 87 | const inc = (num) => ++num 88 | 89 | const twiceUnary = func => num => func(num, num) 90 | 91 | const doubl = num => 2*num 92 | 93 | const square = num => num*num 94 | 95 | const twice = func => (...nums) => func(...nums, ...nums) 96 | 97 | const reverseb = func => (a, b) => func(b, a) 98 | 99 | const reverse = func => (...nums) => func(...nums.reverse()) 100 | 101 | const composeuTwo = (func1, func2) => (num) => func2(func1(num)) 102 | 103 | const composeu = (...funcs) => (num) => { 104 | funcs.forEach(func => num = func(num)) 105 | return num 106 | } 107 | 108 | const composeb = (func1, func2) => (...nums) => func2(nums.pop(), func1(...nums)) 109 | 110 | const composeTwo = (func1, func2) => (...nums) => func2(func1(...nums)) 111 | 112 | const compose = (...funcs) => (...nums) =>{ 113 | funcs.forEach(func => { 114 | nums = typeof(nums) === 'number'? func(nums) : func(...nums) 115 | }) 116 | return nums 117 | } 118 | 119 | const limitb = (func, l) => (a, b) => l-- >=1 ? func(a, b) : undefined 120 | 121 | const limit = (func, l) => (...nums) => l-- >=1 ? func(...nums) : undefined 122 | 123 | function* genFrom(num){ 124 | while(true)yield num++; 125 | } 126 | 127 | // const genTo = (func, l) => () => { 128 | // let num = func.next().value 129 | // if(num < l) return num 130 | // return undefined 131 | // } 132 | 133 | // const genFromTo = (start, end) =>{ 134 | // function* genFrom(){ 135 | // while(start < end)yield start++; 136 | // } 137 | // return () => genFrom().next().value 138 | // } 139 | 140 | // const elementGen = (nums, func) => { 141 | // let index = func.next().value 142 | // while(index !== undefined){ 143 | // yield nums[index] 144 | // index = func.next().value 145 | // } 146 | // yield index 147 | // } 148 | 149 | function* gensymf(s){ 150 | let i = 1; 151 | while(true){ 152 | yield s+i; 153 | i++; 154 | } 155 | } 156 | 157 | function* fibonaccif(f, s){ 158 | yield f 159 | yield s 160 | let sum = f+s 161 | while(true){ 162 | yield sum 163 | f = s 164 | s = sum 165 | sum+=f 166 | } 167 | } 168 | 169 | const counter = num =>{ 170 | return{ 171 | up: () => ++num, 172 | down: () => --num 173 | } 174 | } 175 | 176 | const revocableb = func => { 177 | let flag = true 178 | return { 179 | invoke: (a, b)=> flag? func(a,b): undefined, 180 | revoke: () => flag = false 181 | } 182 | } 183 | 184 | const revocable = func => { 185 | let flag = true 186 | return { 187 | invoke: (...nums)=> flag? func(...nums): undefined, 188 | revoke: () => flag = false 189 | } 190 | } 191 | 192 | const extract = (arr, prop) => arr.map(a => a[prop]) 193 | 194 | const m = (value, source = '') =>{ 195 | return { 196 | value: value, 197 | source: source? source : JSON.stringify(value) 198 | } 199 | } 200 | 201 | const addmTwo = (m1, m2) =>{ 202 | return { 203 | value: m1.value + m2.value, 204 | source: `(${m1.source}+${m2.source})` 205 | } 206 | } 207 | 208 | const addm = (...m) =>{ 209 | return{ 210 | value: m.reduce((acc, num) => acc + num.value, 0), 211 | source: '(' + `${m.reduce((acc, num) => acc+"+"+num.source, '')})`.slice(1) 212 | } 213 | } 214 | 215 | const liftmbM = (func, source) => (m1, m2) =>{ 216 | return { 217 | value: func(m1.value, m2.value), 218 | source: `(${m1.source}${source}${m2.source})` 219 | } 220 | } 221 | 222 | const liftmb = (func, source) => (a, b) =>{ 223 | return { 224 | value: func(a, b), 225 | source: `(${a}${source}${b})` 226 | } 227 | } 228 | 229 | const liftm = (func, source) => (...args) =>{ 230 | let values = args.map(arg => typeof(arg === 'number'? arg:arg.value)) 231 | return { 232 | value: m(func(...values)), 233 | source: `(${values.join(source)})` 234 | } 235 | } 236 | 237 | 238 | 239 | module.exports = { 240 | identity, addb, subb, mulb, minb, maxb, add, sub, mul, min, max, addRecurse, mulRecurse, minRecurse, 241 | maxRecurse, not, acc, accPartial, accRecurse, fill, fillRecurse, set, identityf, addf, liftf, pure, curryb, 242 | curry, inc, twiceUnary, doubl, square, twice, reverseb, reverse, composeuTwo, composeu, composeb, composeTwo, 243 | compose, limitb, limit, genFrom, /*genTo, genFromTo, elementGen, element, collect, filter, filterTail, concatTwo, 244 | concat, concatTail,*/ gensymf,/* gensymff, */fibonaccif, counter, revocableb, revocable, extract, m, addmTwo, addm, liftmbM, 245 | liftmb,/* liftm, exp, expn, addg, liftg, arrayg, continuizeu, continuize, vector, exploitVector, vectorSafe, pubsub, 246 | mapRecurse, filterRecurse */ 247 | }; -------------------------------------------------------------------------------- /Solutions/vyasriday_solutions.js: -------------------------------------------------------------------------------- 1 | const identity = (x) => x; 2 | 3 | const addb = (a, b) => a + b; 4 | 5 | const subb = (a, b) => a - b ; 6 | 7 | const mulb = (a, b) => a * b; 8 | 9 | const minb = (a, b) => a > b ? b : a; 10 | 11 | const maxb = (a, b) => a > b ? a : b; 12 | 13 | const add = (...nums) => nums.reduce((total, current) => total+current, 0) 14 | 15 | const sub = (...nums) => nums.reduce((total, current) => total-current) 16 | 17 | const mul = (...nums) => nums.reduce((total, current) => total*current, 1) 18 | 19 | const min = (...nums) => nums.reduce((min, current) => current < min ? current : min) 20 | 21 | const max = (...nums) => nums.reduce((max, current) => current > max ? current : max) 22 | 23 | const addRecurse = (...nums) => { 24 | return nums.length === 1 ? nums[0]: Number(nums[nums.length-1]) + addRecurse(...nums.slice(0,-1)) 25 | } 26 | 27 | const mulRecurse = (...nums) => { 28 | return nums.length === 1 ? nums[0]: Number(nums[nums.length-1]) * mulRecurse(...nums.slice(0,-1)) 29 | } 30 | 31 | const not = (func) => !func() 32 | 33 | const fill = (num) => Array(num).fill(num); 34 | 35 | const set = (...args) => args.reduce((accumulated, current) => { 36 | if (accumulated.includes(current)) { 37 | return accumulated 38 | } else { 39 | return [...accumulated, current] 40 | } 41 | }, []) 42 | 43 | const identityf = (x) => () => x; 44 | 45 | 46 | const addf = (a) => (b) => a + b; 47 | 48 | 49 | 50 | module.exports = { 51 | identity, 52 | addb, 53 | subb, 54 | mulb, 55 | minb, 56 | maxb, 57 | add, 58 | sub, 59 | mul, 60 | min, 61 | max, 62 | addRecurse, 63 | mulRecurse, 64 | not, 65 | fill, 66 | set, 67 | identityf, 68 | addf 69 | 70 | 71 | } -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 11 | 18 | 19 |
20 |

Hello!

21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | 33 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 2 | array = [1, 2, 3]; 3 | if (array){ 4 | for(array = array.length; array <= 10; array++){ 5 | console.log(array) 6 | } 7 | } 8 | 9 | 10 | op = [1, 2, 3] 11 | num = " over here!"; 12 | if (op === 1, 2, 3){ 13 | for (op = 0; op <= 100; op++){ 14 | console.log(op + num); 15 | } 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "js_fun_practice", 3 | "version": "1.0.0", 4 | "description": "A testing utility for the fun javascript functions", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha || true" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/hazamaswag/JS_Fun_Practice.git" 12 | }, 13 | "author": "hazamaswag", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/hazamaswag/JS_Fun_Practice/issues" 17 | }, 18 | "homepage": "https://github.com/hazamaswag/JS_Fun_Practice#readme", 19 | "devDependencies": { 20 | "chai": "^4.2.0", 21 | "mocha": "^10.2.0", 22 | "mocha-sinon": "^2.1.2", 23 | "sinon": "^9.0.2" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | *{ 2 | margin:0; 3 | padding:0; 4 | } 5 | 6 | 7 | .navbar{ 8 | width:100%; 9 | min-height: 10%; 10 | min-width: 100%; 11 | color:thistle; 12 | float: left; 13 | } 14 | .list{ 15 | display:flex; 16 | flex-direction: row; 17 | list-style: none; 18 | } 19 | li{ 20 | padding:1vw; 21 | } 22 | 23 | li>a{ 24 | text-decoration: none; 25 | color:inherit; 26 | } 27 | .push{ 28 | margin-left:auto; 29 | } 30 | 31 | 32 | 33 | 34 | body{ 35 | background:#07252d; 36 | } 37 | .area h2{ 38 | position:absolute; 39 | top:30%; 40 | font-size:10vw; 41 | letter-spacing: 10px; 42 | width:100%; 43 | color:#0e3742; 44 | -webkit-box-reflect: below 1px linear-gradient(transparent, #0008); 45 | line-height:0.70em; 46 | text-align: center; 47 | text-transform: uppercase; 48 | animation:animate 5s linear infinite; 49 | 50 | } 51 | @keyframes animate{ 52 | 0%,17%,50%,65%,90%,97%{ 53 | color:#0e3742; 54 | 55 | text-shadow: none; 56 | } 57 | 17.1%,50.1%,65.1%,90.1%,97.1%,100%{ 58 | color:#fff; 59 | text-shadow:5px 5px 17px #03b9ff; 60 | 61 | } 62 | } 63 | .area{ 64 | width:100%; 65 | height:100%; 66 | } 67 | .area div{ 68 | animation:animate2 10s linear infinite; 69 | background-color: transparent; 70 | border:1px solid #fff; 71 | position: absolute; 72 | } 73 | div:nth-child(1){ 74 | left:30%; 75 | top:70%; 76 | height:40px; 77 | width:40px; 78 | } 79 | div:nth-child(2){ 80 | left:60%; 81 | top:80%; 82 | height:40px; 83 | width:40px; 84 | } 85 | div:nth-child(3){ 86 | left:10%; 87 | top:30%; 88 | height:40px; 89 | width:40px; 90 | } 91 | div:nth-child(4){ 92 | left:15%; 93 | top:90%; 94 | height:40px; 95 | width:40px; 96 | } 97 | div:nth-child(5){ 98 | left:45%; 99 | top:100%; 100 | height:40px; 101 | width:40px; 102 | animation-delay: 0.5s; 103 | } 104 | div:nth-child(6){ 105 | left:80%; 106 | top:90%; 107 | height:40px; 108 | width:40px; 109 | } 110 | div:nth-child(7){ 111 | left:36%; 112 | top:100%; 113 | height:40px; 114 | width:40px; 115 | animation-delay: 4s; 116 | } 117 | @keyframes animate2{ 118 | 0%{ 119 | transform: translateY(0) rotate(0); 120 | } 121 | 100%{ 122 | transform: translateY(-500px) rotate(360deg); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /test/Amarjit_solutions.js: -------------------------------------------------------------------------------- 1 | const mathModule = require('../Solutions/Amarjit_JS_fun'); 2 | 3 | console.log(mathModule.identity(5)); 4 | console.log(mathModule.addb(3, 7)); 5 | console.log(mathModule.subb(10, 5)); 6 | console.log(mathModule.mulb(2, 3)); 7 | 8 | console.log(mathModule.minb(5,6)); 9 | console.log(mathModule.maxb(3, 7)); 10 | console.log(mathModule.add(10,5,2,3)); 11 | console.log(mathModule.sub(10,2,3)); 12 | console.log(mathModule.mul(3, 7, 5)); 13 | console.log(mathModule.min(10,5,2,3)); 14 | console.log(mathModule.max(10,2,3,11)); 15 | console.log(mathModule.addRecurse(10,2,3,[2,3,[5]],11)); 16 | console.log(mathModule.mulRecurse(10,2,3,[2,3,[5]],11)); 17 | console.log(mathModule.minRecurse(10,2,3,[2,3,[5]],11)); 18 | console.log(mathModule.maxRecurse(10,2,3,[2,3,[5]],11)); 19 | 20 | // Define a test function for not method 21 | const isEven = num => num % 2 === 0; 22 | 23 | // Use the 'not' function from mathModule to get the negation of the result of 'isEven' 24 | const isOdd = mathModule.not(() => isEven(6)); 25 | 26 | console.log(isEven(6)); // Output: true 27 | console.log(isOdd); // Output: false (negation of true) 28 | 29 | // Define a function to add numbers 30 | const add = (a, b) => a + b; 31 | 32 | // Use the acc function to create a new function that accumulates the sum 33 | const accumulateSum = mathModule.acc(add, 0); 34 | 35 | console.log(accumulateSum(1, 2, 3, 4)); // Output: 10 (0 + 1 + 2 + 3 + 4) 36 | 37 | // Define a function to multiply numbers 38 | const multiply = (a, b) => a * b; 39 | 40 | // Use the accPartial function to create a new function that accumulates multiplication 41 | const accumulateProduct = mathModule.accPartial(multiply, 1, 3); 42 | 43 | console.log(accumulateProduct(2, 3, 4, 5)); // Output: 60 (3 * 4 * 5) 44 | 45 | // Define a function to add numbers 46 | const add1 = (a, b) => a + b; 47 | 48 | // Use the accRecurse function to create a new function that accumulates addition 49 | const accumulateSum1 = mathModule.accRecurse(add1, 0); 50 | 51 | console.log(accumulateSum1(1, 2, 3, 4)); // Output: 10 (1 + 2 + 3 + 4) 52 | 53 | const res = mathModule.fill(5); 54 | console.log(res); 55 | 56 | const result2 = mathModule.fillRecurse(5); 57 | console.log(result2); 58 | 59 | const oargs=[1,2,2,3,4,4,5]; 60 | const uargs=mathModule.set(...oargs); 61 | console.log(uargs); 62 | 63 | const fn = mathModule.identityf(7); 64 | console.log(fn()); 65 | 66 | const add2 = mathModule.addf(2); 67 | console.log(add2(3)); 68 | console.log(add2(5)); 69 | console.log(add2(9)); 70 | 71 | const addl = (a,b)=>a+b; 72 | const liftedadd=mathModule.liftf(addl); 73 | const returnl=liftedadd(3)(5); 74 | console.log(returnl); 75 | 76 | 77 | let y = 5, z; 78 | 79 | const result3 = mathModule.pure(20, y); 80 | console.log(result3[1]); // Output: 120 81 | 82 | const result4 = mathModule.pure(25, result3[0]); 83 | console.log(result4[1]); // Output: 175 84 | 85 | // Example usage 86 | const add3 = (x, y) => x + y; 87 | const curriedAdd = mathModule.curryb(add3, 5); 88 | 89 | console.log(curriedAdd(3)); // Output: 8 (5 + 3) 90 | console.log(curriedAdd(10)); // Output: 15 (5 + 10) -------------------------------------------------------------------------------- /test/Marulo_solution.js: -------------------------------------------------------------------------------- 1 | // Write a function identity that takes an argument and returns that argument 2 | 3 | const identity = (name) => { 4 | let question = prompt('What is your name?'); 5 | name = question; 6 | console.log(name); 7 | 8 | } 9 | 10 | const identity2 = (name) =>{ 11 | return name 12 | } 13 | // Write a binary function addb that takes two numbers and returns their sum 14 | 15 | const addb = (a) => (b) => a + b; 16 | const addb2 = (a, b) => a + b 17 | 18 | // Write a binary function minb that takes two numbers and returns the smaller one 19 | const minb = (a, b) => { 20 | if (a > b) { 21 | console.log(a); 22 | } else { 23 | console.log(b); 24 | } 25 | } 26 | 27 | const minb2 = (a, b) => { 28 | if(a < b){ 29 | return a 30 | } else{ 31 | return b 32 | } 33 | } 34 | 35 | // Write a binary function maxb that takes two numbers and returns the larger one 36 | 37 | const maxb = (a, b) => { 38 | if (a > b) { 39 | console.log(a); 40 | } else { 41 | console.log(b); 42 | } 43 | } 44 | 45 | const maxb2 = (a, b) => { 46 | if(a > b){ 47 | return a 48 | } else{ 49 | return b 50 | } 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /test/aal_solution.js: -------------------------------------------------------------------------------- 1 | const assert = require('chai').assert; 2 | const expect = require('chai').expect; 3 | const filename = 'aal_solution'; 4 | const sol = require('../Solutions/' + filename); 5 | require('mocha-sinon'); 6 | 7 | 8 | describe("JS_Fun_Practice", function () { 9 | describe("identity()", function () { 10 | it("takes an argument and returns that argument", function () { 11 | assert.equal(sol.identity(3), 3); 12 | }); 13 | }); 14 | describe("addb(a,b)", function () { 15 | it("takes two numbers and returns their sum", function () { 16 | assert.equal(sol.addb(3, 4), 7); 17 | }); 18 | }); 19 | describe("subb(a,b)", function () { 20 | it("takes two numbers and returns their difference", function () { 21 | assert.equal(sol.subb(3, 4), -1); 22 | }); 23 | }); 24 | describe("mulb(a,b)", function () { 25 | it("takes two numbers and returns their product", function () { 26 | assert.equal(sol.mulb(3, 4), 12); 27 | }); 28 | }); 29 | describe("minb(a,b)", function () { 30 | it("takes two numbers and returns the smaller one", function () { 31 | assert.equal(sol.minb(3, 4), 3); 32 | }); 33 | }); 34 | describe("maxb(a,b)", function () { 35 | it("takes two numbers and returns the larger one", function () { 36 | assert.equal(sol.maxb(3, 4), 4); 37 | }); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /test/justin2172021_solutions.js: -------------------------------------------------------------------------------- 1 | const assert = require('chai').assert; 2 | const expect = require('chai').expect; 3 | const filename = 'usergr_solution'; 4 | const sol = require('../Solutions/' + 'justin2172021_solutions'); 5 | require('mocha-sinon'); 6 | 7 | describe("Justin2172021_JS_Fun_Practice", function () { 8 | describe("identity()", function () { 9 | it("takes an argument and returns that argument", function () { 10 | assert.equal(sol.identity(3), 3); 11 | }); 12 | }); 13 | 14 | describe("addb(a,b)", function () { 15 | it("takes two numbers and returns their sum", function () { 16 | assert.equal(sol.addb(3, 4), 7); 17 | }); 18 | }); 19 | 20 | describe("subb(a,b)", function () { 21 | it("takes two numbers and returns their difference", function () { 22 | assert.equal(sol.subb(3, 4), -1); 23 | }); 24 | }); 25 | 26 | describe("mulb(a,b)", function () { 27 | it("takes two numbers and returns their product", function () { 28 | assert.equal(sol.mulb(3, 4), 12); 29 | }); 30 | }); 31 | 32 | describe("minb(a,b)", function () { 33 | it("takes two numbers and returns the smaller one", function () { 34 | assert.equal(sol.minb(3, 4), 3); 35 | }); 36 | }); 37 | 38 | describe("maxb(a,b)", function () { 39 | it("takes two numbers and returns the larger one", function () { 40 | assert.equal(sol.maxb(3, 4), 4); 41 | }); 42 | }); 43 | 44 | describe("add(...nums)", function () { 45 | it("is an add fuction that is generalized for any amount of arguments", function () { 46 | assert.equal(sol.add(1, 2, 4), 7); 47 | }); 48 | }); 49 | 50 | describe("sub(...nums)", function () { 51 | it("is a sub fuction that is generalized for any amount of arguments", function () { 52 | assert.equal(sol.sub(1, 2, 4), -5); 53 | }); 54 | }); 55 | 56 | describe("mul(...nums)", function () { 57 | it("is a mul fuction that is generalized for any amount of arguments", function () { 58 | assert.equal(sol.mul(1, 2, 4), 8); 59 | }); 60 | }); 61 | 62 | describe("min(...nums)", function () { 63 | it("is a min fuction that is generalized for any amount of arguments", function () { 64 | assert.equal(sol.min(1, 2, 4), 1); 65 | }); 66 | }); 67 | 68 | describe("max(...nums)", function () { 69 | it("is a max fuction that is generalized for any amount of arguments", function () { 70 | assert.equal(sol.max(1, 2, 4), 4); 71 | }); 72 | }); 73 | 74 | describe("addRecurse(...nums)", function () { 75 | it("is an add fuction that is generalized but uses recursion", function () { 76 | assert.equal(sol.addRecurse(1, 2, 4), 7); 77 | }); 78 | }); 79 | 80 | describe("mulRecurse(...nums)", function () { 81 | it("is a mul fuction that is generalized but uses recursion", function () { 82 | assert.equal(sol.mulRecurse(1, 2, 4), 8); 83 | }); 84 | }); 85 | 86 | describe("minRecurse(...nums)", function () { 87 | it("is a min fuction that is generalized but uses recursion", function () { 88 | assert.equal(sol.minRecurse(1, 2, 4), 1); 89 | }); 90 | }); 91 | 92 | describe("maxRecurse(...nums)", function () { 93 | it("is a max fuction that is generalized but uses recursion", function () { 94 | assert.equal(sol.maxRecurse(1, 2, 4), 4); 95 | }); 96 | }); 97 | }); --------------------------------------------------------------------------------