{"pageProps":{"code":{"fcf_format_atomic.ts":{"name":"fcf_format_atomic.ts","content":"type Fmtr = (str: string) => string;\r\n\r\nfunction brackets(str: string) {\r\n  return `(${str})`;\r\n}\r\n\r\nfunction fullstop(str: string) {\r\n  return `${str}.`;\r\n}\r\n\r\nfunction sayHi(name: string, format: Fmtr) {\r\n  return `Hello, ${format(name)}!`;\r\n}\r\n\r\nconst result = sayHi('Hayden', brackets) +\r\n             ' -- ' +\r\n             sayHi('Hayden', fullstop);\r\n\r\nconsole.log(result);\r\n","path":"code/1531/24T1/4.1/fcf_format_atomic.ts","fileext":"ts"},"fcf_format_atomic_alt.ts":{"name":"fcf_format_atomic_alt.ts","content":"type Fmtr = (str: string) => string;\r\n\r\nconst brackets = (str: string) => `(${str})`;\r\nconst fullstop = (str: string) => `${str}.`;\r\nconst sayHi = (name: string, format: Fmtr) => `Hello, ${format(name)}!`;\r\n\r\nconst result = sayHi('Hayden', brackets) +\r\n             ' -- ' +\r\n             sayHi('Hayden', fullstop);\r\n\r\nconsole.log(result);\r\n","path":"code/1531/24T1/4.1/fcf_format_atomic_alt.ts","fileext":"ts"},"fcf_format_loop.ts":{"name":"fcf_format_loop.ts","content":"type Fmtr = (str: string) => string;\r\n\r\nfunction brackets(str: string) {\r\n  return `(${str})`;\r\n}\r\n\r\nfunction lowercase(str: string) {\r\n  return str.toLowerCase();\r\n}\r\n\r\nconst names = ['Hayden', 'Giuliana', 'Tam'];\r\n\r\nfunction formatNames(list: string[], format: Fmtr) {\r\n  const newList = [];\r\n  for (const name of list) {\r\n    newList.push(format(name));\r\n  }\r\n  return newList;\r\n}\r\n\r\nconst newNames = formatNames(names, brackets);\r\nconsole.log(newNames);\r\n\r\nconst lowercaseNames = formatNames(names, lowercase);\r\nconsole.log(lowercaseNames);\r\n","path":"code/1531/24T1/4.1/fcf_format_loop.ts","fileext":"ts"},"fcf_format_loop_anon.ts":{"name":"fcf_format_loop_anon.ts","content":"type Fmtr = (str: string) => string;\r\n\r\nconst names = ['Hayden', 'Giuliana', 'Tam'];\r\n\r\nfunction formatNames(list: string[], format: Fmtr) {\r\n  const newList = [];\r\n  for (const name of list) {\r\n    newList.push(format(name));\r\n  }\r\n  return newList;\r\n}\r\n\r\nconst newNames = formatNames(names, (str) => {\r\n  return `(${str})`;\r\n});\r\n\r\nconsole.log(newNames);\r\n","path":"code/1531/24T1/4.1/fcf_format_loop_anon.ts","fileext":"ts"},"fcf_format_loop_new.ts":{"name":"fcf_format_loop_new.ts","content":"type Fmtr = (str: string) => string;\n\nconst names = ['Hayden', 'Giuliana', 'Tam'];\n\nfunction formatNames(list: string[], format: Fmtr) {\n  const newList: string[] = [];\n  for (const name of list) {\n    newList.push(format(name));\n  }\n  return newList;\n}\n\nconsole.log(formatNames(names, (str: string) => `(${str})`));\nconsole.log(formatNames(names, (str: string) => str.toLowerCase()));\nconsole.log(formatNames(names, (str: string) => `[${str}]`));\n\n","path":"code/1531/24T1/4.1/fcf_format_loop_new.ts","fileext":"ts"},"fcf_var.ts":{"name":"fcf_var.ts","content":"const sayHi = (name: string) => {\n  return `Hello ${name}!`;\n};\nconsole.log(sayHi('Hayden'));\n","path":"code/1531/24T1/4.1/fcf_var.ts","fileext":"ts"},"filter.ts":{"name":"filter.ts","content":"const marks = [65, 72, 81, 40, 56];\r\n\r\nconst isPass = function(mark: number) {\r\n  return mark >= 50;\r\n};\r\n\r\nconst newList = marks.filter(isPass);\r\nconsole.log(newList);\r\n","path":"code/1531/24T1/4.1/filter.ts","fileext":"ts"},"filter_old.ts":{"name":"filter_old.ts","content":"type Student = {\n  name: string;\n  mark: number;\n}\n\nconst students = [\n  {\n    name: 'Hayden',\n    mark: 45, \n  },\n  {\n    name: 'Yuchao',\n    mark: 75, \n  },\n  {\n    name: 'Giuliana',\n    mark: 85, \n  },\n  {\n    name: 'Tam',\n    mark: 85, \n  },\n];\n\nconst newList = students.map((student: Student) => student.mark >= 50);\n\nconsole.log(newList);\n","path":"code/1531/24T1/4.1/filter_old.ts","fileext":"ts"},"filter_stream.ts":{"name":"filter_stream.ts","content":"const marks = [65, 72, 81, 40, 56];\nconst newList = marks.filter((mark) => mark >= 50);\nconsole.log(newList);\n","path":"code/1531/24T1/4.1/filter_stream.ts","fileext":"ts"},"fn_syntax_1.js":{"name":"fn_syntax_1.js","content":"function sum(a, b) {\n  return a + b;\n}\n","path":"code/1531/24T1/4.1/fn_syntax_1.js","fileext":"js"},"fn_syntax_1.ts":{"name":"fn_syntax_1.ts","content":"function sum(a: number, b: number) {\n  return a + b;\n}\n","path":"code/1531/24T1/4.1/fn_syntax_1.ts","fileext":"ts"},"fn_syntax_2.js":{"name":"fn_syntax_2.js","content":"const sum = function(a, b) {\n  return a + b;\n};\n","path":"code/1531/24T1/4.1/fn_syntax_2.js","fileext":"js"},"fn_syntax_2.ts":{"name":"fn_syntax_2.ts","content":"const sum = function(a: number, b: number) {\n  return a + b;\n};\n","path":"code/1531/24T1/4.1/fn_syntax_2.ts","fileext":"ts"},"fn_syntax_3.js":{"name":"fn_syntax_3.js","content":"const sum = (a, b) => {\n  return a + b;\n};\n","path":"code/1531/24T1/4.1/fn_syntax_3.js","fileext":"js"},"fn_syntax_3.ts":{"name":"fn_syntax_3.ts","content":"const sum = (a: number, b: number) => {\n  return a + b;\n};\n","path":"code/1531/24T1/4.1/fn_syntax_3.ts","fileext":"ts"},"fn_syntax_3_compact.ts":{"name":"fn_syntax_3_compact.ts","content":"const sum = (a: number, b: number) => a + b;\n\n// so short!!\n","path":"code/1531/24T1/4.1/fn_syntax_3_compact.ts","fileext":"ts"},"hoc_1.ts":{"name":"hoc_1.ts","content":"function congratMarkPS(name: string) {\n  return `Congratulations ${name} on your pass`;\n}\nfunction congratMarkCR(name: string) {\n  return `Congratulations ${name} on your credit`;\n}\nfunction congratMarkDN(name: string) {\n  return `Congratulations ${name} on your distinction`;\n}\nconsole.log(congratMarkCR('Hayden'));\n","path":"code/1531/24T1/4.1/hoc_1.ts","fileext":"ts"},"hoc_2.ts":{"name":"hoc_2.ts","content":"function congratWrapper(markstr: string, name: string) {\n  return `Congratulations ${name} on your ${markstr}`;\n}\nfunction congratMarkPS(name: string) {\n  return congratWrapper('pass', name);\n}\nfunction congratMarkCR(name: string) {\n  return congratWrapper('credit', name);\n}\nfunction congratMarkDN(name: string) {\n  return congratWrapper('distinction', name);\n}\nconsole.log(congratMarkCR('Hayden'));\n","path":"code/1531/24T1/4.1/hoc_2.ts","fileext":"ts"},"hoc_3.ts":{"name":"hoc_3.ts","content":"const congratWrapper = (markstr: string, name: string) => {\n  return `Congratulations ${name} on your ${markstr}`;\n};\nconst congratMarkPS = (name: string) => {\n  return congratWrapper('pass', name);\n};\nconst congratMarkCR = (name: string) => {\n  return congratWrapper('credit', name);\n};\nconst congratMarkDN = (name: string) => {\n  return congratWrapper('distinction', name);\n};\nconsole.log(congratMarkCR('Hayden'));\n","path":"code/1531/24T1/4.1/hoc_3.ts","fileext":"ts"},"hoc_4.ts":{"name":"hoc_4.ts","content":"function genCongratMark(markstr: string) {\n  const ret = function(name: string) {\n    return `Congratulations ${name} on your ${markstr}`;\n  };\n  return ret;\n}\nconst congratMarkPS = genCongratMark('pass');\nconst congratMarkCR = genCongratMark('credit');\nconst congratMarkDN = genCongratMark('distinction');\n\nconsole.log(congratMarkCR('Hayden'));\n","path":"code/1531/24T1/4.1/hoc_4.ts","fileext":"ts"},"hoc_5.ts":{"name":"hoc_5.ts","content":"const genCongratMark = (markstr: string) => {\n  const ret = (name: string) => {\n    return `Congratulations ${name} on your ${markstr}`;\n  };\n  return ret;\n};\n\nconst congratMarkPS = genCongratMark('pass');\nconst congratMarkCR = genCongratMark('credit');\nconst congratMarkDN = genCongratMark('distinction');\n\nconsole.log(congratMarkCR('Hayden'));\n","path":"code/1531/24T1/4.1/hoc_5.ts","fileext":"ts"},"hoc_6.ts":{"name":"hoc_6.ts","content":"const genCongratMark = (markstr: string) => {\n  return (name: string) => {\n    return `Congratulations ${name} on your ${markstr}`;\n  };\n};\n\nconst congratMarkPS = genCongratMark('pass');\nconst congratMarkCR = genCongratMark('credit');\nconst congratMarkDN = genCongratMark('distinction');\n\nconsole.log(congratMarkCR('Hayden'));\n","path":"code/1531/24T1/4.1/hoc_6.ts","fileext":"ts"},"hoc_7.ts":{"name":"hoc_7.ts","content":"const genCongratMark = (markstr: string) => (name: string) =>\n  `Congratulations ${name} on your ${markstr}`;\n\nconst congratMarkPS = genCongratMark('pass');\nconst congratMarkCR = genCongratMark('credit');\nconst congratMarkDN = genCongratMark('distinction');\n\nconsole.log(congratMarkCR('Hayden'));\n","path":"code/1531/24T1/4.1/hoc_7.ts","fileext":"ts"},"jest.config.js":{"name":"jest.config.js","content":"module.exports = {\n  preset: 'ts-jest',\n  testEnvironment: 'node',\n  maxWorkers: 1,\n};\n","path":"code/1531/24T1/4.1/jest.config.js","fileext":"js"},"many_string_1.ts":{"name":"many_string_1.ts","content":"function manyString(repeat: number, str: string) {\n  let outString = '';\n  for (let i = 0; i < repeat; i++) {\n    outString += str;\n  }\n  return outString;\n}\nconsole.log(manyString(5, 'hello '));\n","path":"code/1531/24T1/4.1/many_string_1.ts","fileext":"ts"},"many_string_2.ts":{"name":"many_string_2.ts","content":"const manyString = function(repeat: number, str: string) {\n  let outString = '';\n  for (let i = 0; i < repeat; i++) {\n    outString += str;\n  }\n  return outString;\n};\nconsole.log(manyString(5, 'hello '));\n","path":"code/1531/24T1/4.1/many_string_2.ts","fileext":"ts"},"many_string_3.ts":{"name":"many_string_3.ts","content":"const manyString = (repeat: number, str: string) => {\n  let outString = '';\n  for (let i = 0; i < repeat; i++) {\n    outString += str;\n  }\n  return outString;\n};\nconsole.log(manyString(5, 'hello '));\n","path":"code/1531/24T1/4.1/many_string_3.ts","fileext":"ts"},"map.ts":{"name":"map.ts","content":"const tutors = [\r\n  'Simon',\r\n  'Teresa',\r\n  'Kaiqi',\r\n  'Michelle',\r\n];\r\n\r\nconst shout = function(str: string) {\r\n  return `${str.toUpperCase()}!!!`;\r\n};\r\n\r\nconst newList = tutors.map(shout);\r\nconsole.log(newList);\r\n","path":"code/1531/24T1/4.1/map.ts","fileext":"ts"},"map_old.ts":{"name":"map_old.ts","content":"const tutors = [\n  'Simon',\n  'Teresa',\n  'Kaiqi',\n  'Michelle',\n];\n\nconst loudTutors = tutors.map((str: string) => {\n  return `${str.toUpperCase()}!!!`;\n});\n\nconsole.log(loudTutors);\n","path":"code/1531/24T1/4.1/map_old.ts","fileext":"ts"},"map_stream.ts":{"name":"map_stream.ts","content":"const tutors = ['Simon', 'Teresa', 'Kaiqi', 'Michelle'];\nconst newList = tutors.map((string) => `${string.toUpperCase()}!!!`);\nconsole.log(newList);\n","path":"code/1531/24T1/4.1/map_stream.ts","fileext":"ts"},"mapfilterreduce.ts":{"name":"mapfilterreduce.ts","content":"const marks = [39, 43.2, 48.6, 24, 33.6];\r\nconsole.log(marks);\r\nconst normalisedMarks = marks.map(m => 100 * m / 60);\r\nconsole.log(normalisedMarks);\r\nconst passingMarks = normalisedMarks.filter(m => m >= 50);\r\nconsole.log(passingMarks);\r\nconst total = passingMarks.reduce((a, b) => a + b, 0);\r\nconsole.log(total);\r\nconst average = total / passingMarks.length;\r\nconsole.log(average);\r\n","path":"code/1531/24T1/4.1/mapfilterreduce.ts","fileext":"ts"},"package.json":{"name":"package.json","content":"{\n  \"name\": \"env2\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"jest src\",\n    \"tsc\": \"tsc --noImplicitAny\",\n    \"lint\": \"eslint src/**.ts\",\n    \"lint-fix\": \"eslint --fix src/**.ts\",\n    \"ts-node\": \"ts-node\",\n    \"jest\": \"jest\",\n    \"nodemon\": \"nodemon\",\n    \"ts-node-coverage\": \"nyc --reporter=text --reporter=lcov ts-node\"\n  },\n  \"author\": \"\",\n  \"license\": \"ISC\",\n  \"devDependencies\": {\n    \"@types/express\": \"^4.17.13\",\n    \"@types/http-errors\": \"^1.8.2\",\n    \"@types/jest\": \"^27.5.0\",\n    \"@types/node\": \"^17.0.27\",\n    \"@types/prompt-sync\": \"^4.1.1\",\n    \"@typescript-eslint/eslint-plugin\": \"^5.21.0\",\n    \"@typescript-eslint/parser\": \"^5.21.0\",\n    \"eslint\": \"^8.14.0\",\n    \"eslint-plugin-jest\": \"^26.1.5\",\n    \"jest\": \"^28.1.0\",\n    \"middleware-http-errors\": \"^0.1.0\",\n    \"nodemon\": \"^2.0.16\",\n    \"nyc\": \"^15.1.0\",\n    \"ts-jest\": \"^28.0.2\",\n    \"typescript\": \"^4.6.3\"\n  },\n  \"dependencies\": {\n    \"express\": \"^4.18.0\",\n    \"http-errors\": \"^2.0.0\",\n    \"sync-request\": \"^6.1.0\",\n    \"ts-node\": \"^10.7.0\"\n  }\n}\n","path":"code/1531/24T1/4.1/package.json","fileext":"json"},"read_async.ts":{"name":"read_async.ts","content":"import fs from 'fs';\r\n\r\nfunction handleFile(error: any, data: any) {\r\n  if (error) {\r\n    console.error(error);\r\n  } else {\r\n    console.log(data);\r\n  }\r\n}\r\n\r\nfs.readFile('dummy.txt', { flag: 'r' }, handleFile);\r\n\r\nconsole.log('Finished!');\r\n","path":"code/1531/24T1/4.1/read_async.ts","fileext":"ts"},"read_sync.ts":{"name":"read_sync.ts","content":"import fs from 'fs';\r\n\r\nconst data = fs.readFileSync('dummy.txt', { flag: 'r' });\r\n\r\nconsole.log(data);\r\nconsole.log('Finished!');\r\n","path":"code/1531/24T1/4.1/read_sync.ts","fileext":"ts"},"reduce.ts":{"name":"reduce.ts","content":"type Student = {\r\n  name: string;\r\n  mark: number;\r\n}\r\n\r\nconst students: Student[] = [\r\n  { name: 'Amy', mark: 55 },\r\n  { name: 'Bob', mark: 43 },\r\n  { name: 'Cap', mark: 34 },\r\n  { name: 'Dex', mark: 23 },\r\n];\r\n\r\nconst sum = (prev: number, curr: Student) => {\r\n  return prev + curr.mark;\r\n};\r\n\r\nconst single = students.reduce(sum, 0);\r\nconsole.log(single);\r\n","path":"code/1531/24T1/4.1/reduce.ts","fileext":"ts"},"reduce_old.ts":{"name":"reduce_old.ts","content":"const students = [\n  { name: 'Amy', mark: 55 },\n  { name: 'Bob', mark: 43 },\n  { name: 'Cap', mark: 34 },\n  { name: 'Dex', mark: 23 },\n];\n\nlet single = 0;\nfor (const student of students) {\n  single += student.mark;\n}\nconsole.log(single);\n","path":"code/1531/24T1/4.1/reduce_old.ts","fileext":"ts"},"reduce_stream.ts":{"name":"reduce_stream.ts","content":"const students = [\n  { name: 'Amy', mark: 55 },\n  { name: 'Bob', mark: 43 },\n  { name: 'Cap', mark: 34 },\n  { name: 'Dex', mark: 23 },\n];\nconst single = students.reduce((prev, curr) => prev + curr.mark, 0);\nconsole.log(single);\n","path":"code/1531/24T1/4.1/reduce_stream.ts","fileext":"ts"},"tsconfig.json":{"name":"tsconfig.json","content":"{\n    \"compilerOptions\": {\n        \"esModuleInterop\": true,\n        \"noImplicitAny\": false,\n        \"noEmit\": true,\n        \"resolveJsonModule\": true\n    },\n    \"exclude\": [\n      \"**/**_broken.ts\"\n    ]\n}\n\n","path":"code/1531/24T1/4.1/tsconfig.json","fileext":"json"}}},"__N_SSG":true}