{"id":18623734,"url":"https://github.com/clifftech123/ts_fun_practice","last_synced_at":"2025-11-03T18:30:31.200Z","repository":{"id":165963900,"uuid":"639637224","full_name":"Clifftech123/TS_Fun_Practice","owner":"Clifftech123","description":"Collection of small and enjoyable functional programming exercises in TypeScrip","archived":false,"fork":false,"pushed_at":"2023-05-22T22:07:45.000Z","size":8357,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-27T05:25:16.736Z","etag":null,"topics":["functional-programming","javascript","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Clifftech123.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-11T22:19:53.000Z","updated_at":"2023-05-16T14:25:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"05b97579-e220-4403-9c9d-2c1e30065239","html_url":"https://github.com/Clifftech123/TS_Fun_Practice","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clifftech123%2FTS_Fun_Practice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clifftech123%2FTS_Fun_Practice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clifftech123%2FTS_Fun_Practice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Clifftech123%2FTS_Fun_Practice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Clifftech123","download_url":"https://codeload.github.com/Clifftech123/TS_Fun_Practice/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239418576,"owners_count":19635208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functional-programming","javascript","typescript"],"created_at":"2024-11-07T04:25:53.961Z","updated_at":"2025-11-03T18:30:30.666Z","avatar_url":"https://github.com/Clifftech123.png","language":"TypeScript","readme":"# Typescript Function practice\n\nWelcome to a collection of small and enjoyable functional programming exercises in TypeScript. This repository draws inspiration from JS-fun-Practice, created by the amazing community at Zero to Mastery. Check them out at [Zero to Mastery!](https://zerotomastery.io/).\n\nWhile Zero to Mastery's [JS-fun-Practice ](https://github.com/zero-to-mastery/JS_Fun_Practice) focused on JavaScript, I've taken up the challenge of reimplementing those exercises in TypeScript. As a result, this repository is entirely TypeScript-based.\n\nBelow, you'll find the exercises I've completed so far, and I'll continue to add more over time.\n\n## Solutions Exercises\n\n1.  Write a function identity that takes an argument and returns that argument\n\n```typescript\nconst identity = (arg: any) =\u003e {\n  return arg;\n};\nconst dentity_Result = identity(3);\nconsole.log(dentity_Result); // output: 5\n```\n\n2.  Write a binary function addb that takes two numbers and returns their sum\n\n```typescript\nconst addb = (num1: number, num2: number) =\u003e {\n  return num1 + num2;\n};\n\nconst addb_Result = addb(4, 4);\nconsole.log(addb_Result); // output:  8\n```\n\n3.  Write a binary function subb that takes two numbers and returns their difference\n\n```typescript\nexport const subb = (num1: number, num2: number) =\u003e {\n  return num1 - num2;\n};\n\nconst subb_Result = subb(10, 4);\nconsole.log(subb_Result); // output: 6\n```\n\n4. Write a binary function mulb that takes two numbers and returns their product.\n\n```typescript\nconst mulb = (num1: number, num2: number) =\u003e {\n  return num1 * num2;\n};\n\nconst mulb_Result = mulb(3, 4);\nconsole.log(mulb_Result); // output: 12\n```\n\n5. Write a function minb that takes two numbers and returns the smaller one.\n\n```typescript\nconst minb = (num1: number, num2: number) =\u003e {\n  return Math.min(num1, num2);\n};\n\nconst minb_Result = minb(3, 4);\nconsole.log(minb_Result); // output: 3\n```\n\n6. Write a function maxb that takes two numbers and returns the larger one.\n\n```typescript\nconst maxb = (num1: number, num2: number) =\u003e {\n  return Math.max(num1, num2);\n};\nconst maxb_Result = maxb(3, 4);\nconsole.log(maxb_Result); // output: 4`\n\n```\n\n7. Write a function add that is generalized for any amount of arguments\n\n```typescript\n const add = (...nums: number[]) =\u003e {\n  return nums.reduce((acc, curr) =\u003e acc + curr, 0);\n};\n\nconst add_Result = add(1, 2, 4);\nconsole.log(add_Result); // output: 7\n\n```\n\n8. Write a function sub that is generalized for any amount of arguments\n\n```typescript\n const sub = (...nums: number[]) =\u003e {\n  return nums.reduce((acc, curr) =\u003e acc - curr);\n};\n\nconst sub_Result = sub(1, 2, 4);\nconsole.log(sub_Result); // output: -5\n\n```\n\n\n9. Write a function mul that is generalized for any amount of arguments\n\n```typescript\n\nconst mul = (...nums: number[]) =\u003e {\n  return nums.reduce((acc, curr) =\u003e acc * curr);\n};\n\nconst mul_Result = mul(1, 2, 4);\nconsole.log(mul_Result); // output: 8\n\n```\n\n10. Write a function min that is generalized for any amount of arguments\n\n```typescript\n\n\nconst min = (...nums: number[]) =\u003e {\n  return nums.reduce((acc, curr) =\u003e Math.min(acc, curr));\n};\n\nconst min_Result = min(1, 2, 4);\nconsole.log(min_Result); // output: 1\n\n```\n\n11. Write a function max that is generalized for any amount of arguments\n\n```typescript\n\nconst max = (...nums: number[]) =\u003e {\n  return nums.reduce((acc, curr) =\u003e Math.max(acc, curr));\n};\n\nconst max_Result = max(1, 2, 4);\nconsole.log(max_Result); // output: 4\n\n```\n\n\n12. Write a function addRecurse that is the generalized add function but uses recursion\n\n```typescript\n\nconst addRecurse = (...nums: number[]):number =\u003e {\n  if (nums.length === 1) return nums[0];\n  return nums[0] + addRecurse(...nums.slice(1));\n};\n\nconst addRecurse_Result = addRecurse(1, 2, 4);\nconsole.log(addRecurse_Result); // output: 7\n\n```\n\n\n13. Write a function mulRecurse that is the generalized mul function but uses recursion\n```typescript\n\n const mulRecurse = (...nums: number[]): number =\u003e {\n  if (nums.length === 1) return nums[0];\n  return nums[0] * mulRecurse(...nums.slice(1));\n};\n\n// example usage\nconst mulRecurse_Result = mulRecurse(2, 2, 4);\nconsole.log(mulRecurse_Result); // output: 8\n\n```\n14. Write a function minRecurse that is the generalized min function but uses recursion\n\n```typescript\nconst minRecurse = (...nums: number[]): number =\u003e {\n  if (nums.length === 1) {\n    return nums[0];\n  }\n  const minn = minRecurse(...nums.slice(1));\n  return Math.min(nums[0], minn);\n};\n\n// example usage\nconst minRecurse_Result = minRecurse(1, 2, 4);\nconsole.log(minRecurse_Result); // output: 2\n\n```\n\n\n15. Write a function maxRecurse that is the generalized max function but uses recursion\n\n```typescript\n\nexport const maxRecurse = (...nums: number[]): number =\u003e {\n  if (nums.length === 1) {\n    return nums[0];\n  } else {\n    const maxx = maxRecurse(...nums.slice(1));\n    return Math.max(nums[0], maxx);\n  }\n};\n\n//  example usage\nconst maxRecurse_Result = maxRecurse(1, 2, 4);\nconsole.log(maxRecurse_Result); // output: 4\n\n```\n\n\n16. Write a function not that takes a function and returns the negation of its result\n\n```typescript\n\n function not\u003cT\u003e(f: (x: T) =\u003e boolean): (x: T) =\u003e boolean {\n  return (x: T) =\u003e !f(x);\n}\n\n// Easy  ussage\nconst isEven = (x: number) =\u003e x % 2 === 0;\nconst isOdd = not(isEven);\nconsole.log(isEven(2)); // true\nconsole.log(isOdd(2)); // false \n\n```\n\n\n\n17. 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\n\n```typescript\n\n\ntype AccumulatorFunction\u003cT, R\u003e = (acc: R, val: T) =\u003e R;\n\n  export  function acc\u003cT, R\u003e(\n  fn: AccumulatorFunction\u003cT, R\u003e,\n  initialValue: R\n): AccumulatorFunction\u003cT, R\u003e {\n  return (acc: R, val: T) =\u003e fn(acc, val);\n}\n\n// Example usage\nconst sum: AccumulatorFunction\u003cnumber, number\u003e = (acc, val) =\u003e acc + val;\nconst accumulator = acc(sum, 0);\nconsole.log(accumulator(1, 2)); // Output: 3\nconsole.log(accumulator(3, 4)); // Output: 7\nconsole.log(accumulator(5, 6)); // Output: 11\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclifftech123%2Fts_fun_practice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclifftech123%2Fts_fun_practice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclifftech123%2Fts_fun_practice/lists"}