{"pageProps":{"code":{"3.3_example_aliases.ts":{"name":"3.3_example_aliases.ts","content":"type ListItem = string | number;\n\nfunction create10List(item: ListItem) {\n  const arr: ListItem[] = [];\n  for (let i = 0; i < 10; i++) {\n    arr.push(item);\n  }\n  return arr;\n}\n","path":"code/1531/23T1/env2/src/3.3_example_aliases.ts","fileext":"ts"},"3.3_example_any.ts":{"name":"3.3_example_any.ts","content":"// @ts-nocheck\n\nfunction hello(name: any): any {\n  return `Hello ${name}!`;\n}\n\nfunction substring(str: any, start: any, end: any) {\n  return null;\n}\n\ntype Person = any;\nconst person: Person = {\n  name: 'Hayden',\n};\n","path":"code/1531/23T1/env2/src/3.3_example_any.ts","fileext":"ts"},"3.3_example_functions.ts":{"name":"3.3_example_functions.ts","content":"function hello(name: string): string {\n  return `Hello ${name}!`;\n}\n","path":"code/1531/23T1/env2/src/3.3_example_functions.ts","fileext":"ts"},"3.3_example_lists.ts":{"name":"3.3_example_lists.ts","content":"function create10List(item: string | number) {\n  const arr: Array<string | number> = [];\n  for (let i = 0; i < 10; i++) {\n    arr.push(item);\n  }\n  return arr;\n}\n","path":"code/1531/23T1/env2/src/3.3_example_lists.ts","fileext":"ts"},"3.3_example_literals.ts":{"name":"3.3_example_literals.ts","content":"type visibility = 'Private' | 'Public';\n\nfunction createChannel(name: string, visibility: visibility) {\n  // Do things\n}\n","path":"code/1531/23T1/env2/src/3.3_example_literals.ts","fileext":"ts"},"3.3_example_objects.ts":{"name":"3.3_example_objects.ts","content":"type Person = {\n  name: string;\n  age?: number;\n  height?: number;\n}\n\nconst person: Person = {\n  name: 'Hayden',\n};\n\nperson.age = 5;\n","path":"code/1531/23T1/env2/src/3.3_example_objects.ts","fileext":"ts"},"3.3_example_optionals.ts":{"name":"3.3_example_optionals.ts","content":"// Note:\n//   end?: number\n// = end: number | undefined\n\nfunction substring(str: string, start: number, end?: number) {\n  let newString = '';\n  const modifiedEnd = end || str.length;\n  // ^ What about end ?? str.length\n  for (let i = start; i < modifiedEnd; i++) {\n    newString += str[i];\n  }\n  return newString;\n}\n\nconsole.log(substring('hayden', 0, 3));\nconsole.log(substring('hayden', 2));\n","path":"code/1531/23T1/env2/src/3.3_example_optionals.ts","fileext":"ts"},"3.3_example_unions.ts":{"name":"3.3_example_unions.ts","content":"function printIfReady(ready: boolean | number) {\n  if (ready === true || (!ready && ready !== 0)) {\n    console.log('Ready!');\n  }\n}\nprintIfReady(1);\nprintIfReady(2);\nprintIfReady(0);\nprintIfReady(true);\nprintIfReady(false);\n","path":"code/1531/23T1/env2/src/3.3_example_unions.ts","fileext":"ts"},"3.3_gitlab-ci_type.yml":{"name":"3.3_gitlab-ci_type.yml","content":"image: comp1531/basic:latest\n\nstages:\n  - checks\n\ntesting:\n  stage: checks\n  script:\n    - npm run test\n\ntypecheck:\n  stage: checks\n  script:\n    - npm run tsc\n","path":"code/1531/23T1/env2/src/3.3_gitlab-ci_type.yml","fileext":"yml"},"3.3_many_string_rude.js":{"name":"3.3_many_string_rude.js","content":"function manyString(repeat, str) {\n  let outString = '';\n  for (let i = 0; i < repeat; i++) {\n    outString += str;\n  }\n  return outString;\n}\nconsole.log(manyString('hello ', 5));\n","path":"code/1531/23T1/env2/src/3.3_many_string_rude.js","fileext":"js"},"3.3_many_string_runtime.js":{"name":"3.3_many_string_runtime.js","content":"function manyString(repeat, str) {\n  if (repeat instanceof 'number') {\n    console.error('repeat argument is not a number');\n    return undefined;\n  }\n  if (str instanceof 'string') {\n    console.error('str argument is not a string');\n    return undefined;\n  }\n  let outString = '';\n  for (let i = 0; i < repeat; i++) {\n    outString += str;\n  }\n  return outString;\n}\nconsole.log(manyString('hello ', 5));\n","path":"code/1531/23T1/env2/src/3.3_many_string_runtime.js","fileext":"js"},"3.3_mycode.ts":{"name":"3.3_mycode.ts","content":"function sum(a: number, b: number) {\n  return a + b;\n}\nconsole.log(sum(1, 2));\n","path":"code/1531/23T1/env2/src/3.3_mycode.ts","fileext":"ts"},"3.3_mycode_broken.ts":{"name":"3.3_mycode_broken.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('hello ', 5));\n","path":"code/1531/23T1/env2/src/3.3_mycode_broken.ts","fileext":"ts"},"3.4_gitlab-ci_lint.yml":{"name":"3.4_gitlab-ci_lint.yml","content":"image: comp1531/basic:latest\n\ncache:\n  paths:\n    - node_modules\n    \nstages:\n  - checks\n\ntesting:\n  stage: checks\n  script:\n    - npm run test\n\ntypecheck:\n  stage: checks\n  script:\n    - npm run tsc\n\nlinting:\n  stage: checks\n  script:\n    - npm run lint\n","path":"code/1531/23T1/env2/src/3.4_gitlab-ci_lint.yml","fileext":"yml"},"3.4_style_bad.js":{"name":"3.4_style_bad.js","content":"/* eslint-disable */\nfunction a(b,c){\n let d = '';\n  for\n   (let i = 0; i < b; i++) \nd += c;\n return d;\n}\nconsole.log(a(5, 'hello '));\n","path":"code/1531/23T1/env2/src/3.4_style_bad.js","fileext":"js"},"3.4_style_good.js":{"name":"3.4_style_good.js","content":"function manyString(repeat, str) {\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/23T1/env2/src/3.4_style_good.js","fileext":"js"},"4.1_fcf_format_atomic.ts":{"name":"4.1_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/23T1/env2/src/4.1_fcf_format_atomic.ts","fileext":"ts"},"4.1_fcf_format_atomic_alt.ts":{"name":"4.1_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/23T1/env2/src/4.1_fcf_format_atomic_alt.ts","fileext":"ts"},"4.1_fcf_format_loop.ts":{"name":"4.1_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\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","path":"code/1531/23T1/env2/src/4.1_fcf_format_loop.ts","fileext":"ts"},"4.1_fcf_format_loop_anon.ts":{"name":"4.1_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/23T1/env2/src/4.1_fcf_format_loop_anon.ts","fileext":"ts"},"4.1_fcf_format_loop_new.ts":{"name":"4.1_fcf_format_loop_new.ts","content":"type Fmtr = (str: string) => string;\n\nconst brackets = (str: string) => {\n  return `(${str})`;\n};\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\nconst newNames = formatNames(names, brackets);\nconsole.log(newNames);\n","path":"code/1531/23T1/env2/src/4.1_fcf_format_loop_new.ts","fileext":"ts"},"4.1_fcf_var.ts":{"name":"4.1_fcf_var.ts","content":"const sayHi = (name: string) => {\n  return `Hello ${name}!`;\n};\nconsole.log(sayHi('Hayden'));\n","path":"code/1531/23T1/env2/src/4.1_fcf_var.ts","fileext":"ts"},"4.1_filter.ts":{"name":"4.1_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/23T1/env2/src/4.1_filter.ts","fileext":"ts"},"4.1_filter_old.ts":{"name":"4.1_filter_old.ts","content":"const marks = [65, 72, 81, 40, 56];\n\nconst isPass = function(mark: number) {\n  return mark >= 50;\n};\n\nconst newList = [];\nfor (const mark of marks) {\n  if (isPass(mark)) {\n    newList.push(mark);\n  }\n}\nconsole.log(newList);\n","path":"code/1531/23T1/env2/src/4.1_filter_old.ts","fileext":"ts"},"4.1_filter_stream.ts":{"name":"4.1_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/23T1/env2/src/4.1_filter_stream.ts","fileext":"ts"},"4.1_fn_syntax_1.js":{"name":"4.1_fn_syntax_1.js","content":"function sum(a, b) {\n  return a + b;\n}\n","path":"code/1531/23T1/env2/src/4.1_fn_syntax_1.js","fileext":"js"},"4.1_fn_syntax_1.ts":{"name":"4.1_fn_syntax_1.ts","content":"function sum(a: number, b: number) {\n  return a + b;\n}\n","path":"code/1531/23T1/env2/src/4.1_fn_syntax_1.ts","fileext":"ts"},"4.1_fn_syntax_2.js":{"name":"4.1_fn_syntax_2.js","content":"const sum = function(a, b) {\n  return a + b;\n};\n","path":"code/1531/23T1/env2/src/4.1_fn_syntax_2.js","fileext":"js"},"4.1_fn_syntax_2.ts":{"name":"4.1_fn_syntax_2.ts","content":"const sum = function(a: number, b: number) {\n  return a + b;\n};\n","path":"code/1531/23T1/env2/src/4.1_fn_syntax_2.ts","fileext":"ts"},"4.1_fn_syntax_3.js":{"name":"4.1_fn_syntax_3.js","content":"const sum = (a, b) => {\n  return a + b;\n};\n","path":"code/1531/23T1/env2/src/4.1_fn_syntax_3.js","fileext":"js"},"4.1_fn_syntax_3.ts":{"name":"4.1_fn_syntax_3.ts","content":"const sum = (a: number, b: number) => {\n  return a + b;\n};\n","path":"code/1531/23T1/env2/src/4.1_fn_syntax_3.ts","fileext":"ts"},"4.1_fn_syntax_3_compact.ts":{"name":"4.1_fn_syntax_3_compact.ts","content":"const sum = (a: number, b: number) => a + b;\n\n// so short!!\n","path":"code/1531/23T1/env2/src/4.1_fn_syntax_3_compact.ts","fileext":"ts"},"4.1_hoc_1.ts":{"name":"4.1_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/23T1/env2/src/4.1_hoc_1.ts","fileext":"ts"},"4.1_hoc_2.ts":{"name":"4.1_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/23T1/env2/src/4.1_hoc_2.ts","fileext":"ts"},"4.1_hoc_3.ts":{"name":"4.1_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/23T1/env2/src/4.1_hoc_3.ts","fileext":"ts"},"4.1_hoc_4.ts":{"name":"4.1_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/23T1/env2/src/4.1_hoc_4.ts","fileext":"ts"},"4.1_hoc_5.ts":{"name":"4.1_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/23T1/env2/src/4.1_hoc_5.ts","fileext":"ts"},"4.1_hoc_6.ts":{"name":"4.1_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/23T1/env2/src/4.1_hoc_6.ts","fileext":"ts"},"4.1_hoc_7.ts":{"name":"4.1_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/23T1/env2/src/4.1_hoc_7.ts","fileext":"ts"},"4.1_many_string_1.ts":{"name":"4.1_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/23T1/env2/src/4.1_many_string_1.ts","fileext":"ts"},"4.1_many_string_2.ts":{"name":"4.1_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/23T1/env2/src/4.1_many_string_2.ts","fileext":"ts"},"4.1_many_string_3.ts":{"name":"4.1_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/23T1/env2/src/4.1_many_string_3.ts","fileext":"ts"},"4.1_map.ts":{"name":"4.1_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/23T1/env2/src/4.1_map.ts","fileext":"ts"},"4.1_map_old.ts":{"name":"4.1_map_old.ts","content":"const tutors = [\n  'Simon',\n  'Teresa',\n  'Kaiqi',\n  'Michelle',\n];\n\nconst shout = function(str: string) {\n  return `${str.toUpperCase()}!!!`;\n};\n\nconst newList = [];\nfor (const tutor of tutors) {\n  const newTutor = shout(tutor);\n  newList.push(newTutor);\n}\nconsole.log(newList);\n","path":"code/1531/23T1/env2/src/4.1_map_old.ts","fileext":"ts"},"4.1_map_stream.ts":{"name":"4.1_map_stream.ts","content":"const tutors = ['Simon', 'Teresa', 'Kaiqi', 'Michelle'];\nconst newList = tutors.map((string) => `${string.toUpperCase()}!!!`);\nconsole.log(newList);\n","path":"code/1531/23T1/env2/src/4.1_map_stream.ts","fileext":"ts"},"4.1_mapfilterreduce.ts":{"name":"4.1_mapfilterreduce.ts","content":"const marks = [39, 43.2, 48.6, 24, 33.6];\r\nconst normalisedMarks = marks.map(m => 100 * m / 60);\r\nconst passingMarks = normalisedMarks.filter(m => m >= 50);\r\nconst total = passingMarks.reduce((a, b) => a + b, 0);\r\nconst average = total / passingMarks.length;\r\nconsole.log(average);\r\n","path":"code/1531/23T1/env2/src/4.1_mapfilterreduce.ts","fileext":"ts"},"4.1_read_async.ts":{"name":"4.1_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/23T1/env2/src/4.1_read_async.ts","fileext":"ts"},"4.1_read_sync.ts":{"name":"4.1_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/23T1/env2/src/4.1_read_sync.ts","fileext":"ts"},"4.1_reduce.ts":{"name":"4.1_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/23T1/env2/src/4.1_reduce.ts","fileext":"ts"},"4.1_reduce_old.ts":{"name":"4.1_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/23T1/env2/src/4.1_reduce_old.ts","fileext":"ts"},"4.1_reduce_stream.ts":{"name":"4.1_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/23T1/env2/src/4.1_reduce_stream.ts","fileext":"ts"},"4.2_crud.ts":{"name":"4.2_crud.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3001;\n\napp.use(express.text());\n\napp.get('/apple', (req, res) => {\n  const name = req.query.name;\n  res.send(JSON.stringify({\n    msg: `Hi ${name}, thanks for sending apple!`,\n  }));\n});\n\n// same for .put and .delete\napp.post('/orange', (req, res) => {\n  const body = JSON.parse(req.body);\n  const name = body.name;\n  res.send(JSON.stringify({\n    msg: `Hi ${name}, thanks for sending orange!`,\n  }));\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/23T1/env2/src/4.2_crud.ts","fileext":"ts"},"4.2_crud_json.ts":{"name":"4.2_crud_json.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3001;\n\napp.use(express.json());\n\napp.get('/apple', (req, res) => {\n  const name = req.query.name;\n  res.json({\n    msg: `Hi ${name}, thanks for sending apple!`,\n  });\n});\n\n// same for .put and .delete\napp.post('/orange', (req, res) => {\n  const name = req.body.name;\n  res.json({\n    msg: `Hi ${name}, thanks for sending orange!`,\n  });\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/23T1/env2/src/4.2_crud_json.ts","fileext":"ts"},"4.2_express_basic.ts":{"name":"4.2_express_basic.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3000;\n\napp.use(express.text());\n\napp.get('/', (req, res) => {\n  res.send('Hello World!');\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/23T1/env2/src/4.2_express_basic.ts","fileext":"ts"},"4.2_requests.test.ts":{"name":"4.2_requests.test.ts","content":"import request from 'sync-request';\n\ndescribe('Test Apple', () => {\n  test('If it returns a name string successfully', () => {\n    const res = request(\n      'GET',\n      'http://localhost:3001/apple',\n      {\n        qs: {\n          name: 'Hayden',\n        },\n      }\n    );\n    const bodyObj = JSON.parse(String(res.getBody()));\n    expect(bodyObj.msg).toBe('Hi Hayden, thanks for sending apple!');\n  });\n});\ndescribe('Test Orange', () => {\n  test('If it returns a name string successfully', () => {\n    const res = request(\n      'POST',\n      'http://localhost:3001/orange',\n      {\n        body: JSON.stringify({ name: 'Hayden' }),\n        headers: {\n          'Content-type': 'application/json',\n        },\n      }\n    );\n    const bodyObj = JSON.parse(String(res.getBody()));\n    expect(bodyObj.msg).toBe('Hi Hayden, thanks for sending orange!');\n  });\n});\n","path":"code/1531/23T1/env2/src/4.2_requests.test.ts","fileext":"ts"},"4.2_requests.ts":{"name":"4.2_requests.ts","content":"import request from 'sync-request';\n\nconst res = request(\n  'GET',\n  'http://localhost:3001/apple?name=Hayden'\n);\nconsole.log(JSON.parse(String(res.getBody())));\n","path":"code/1531/23T1/env2/src/4.2_requests.ts","fileext":"ts"},"4.2_requests_json.test.ts":{"name":"4.2_requests_json.test.ts","content":"import request from 'sync-request';\n\ndescribe('Test Apple', () => {\n  test('If it returns a name string successfully', () => {\n    const res = request(\n      'GET',\n      'http://localhost:3001/apple',\n      {\n        qs: {\n          name: 'Hayden',\n        },\n      }\n    );\n    const bodyObj = JSON.parse(String(res.getBody()));\n    expect(bodyObj.msg).toBe('Hi Hayden, thanks for sending apple!');\n  });\n});\ndescribe('Test Orange', () => {\n  test('If it returns a name string successfully', () => {\n    const res = request(\n      'POST',\n      'http://localhost:3001/orange',\n      {\n        json: { name: 'Hayden' },\n      }\n    );\n    const bodyObj = JSON.parse(String(res.getBody()));\n    expect(bodyObj.msg).toBe('Hi Hayden, thanks for sending orange!');\n  });\n});\n","path":"code/1531/23T1/env2/src/4.2_requests_json.test.ts","fileext":"ts"},"5.3_catch.test.ts":{"name":"5.3_catch.test.ts","content":"import { sqrt } from './5.2_sqrt';\n\ndescribe('sqrt correctness', () => {\n  test('deals with valid bases', () => {\n    expect(sqrt(4)).toEqual(2);\n    expect(sqrt(2)).toBeCloseTo(1.414213, 5);\n  });\n  test('throws error on negatives', () => {\n    // Note that these require a function, not result\n    expect(() => sqrt(-2)).toThrow('Error: Input < 0');\n    expect(() => sqrt(-5)).toThrowError('Error: Input < 0');\n  });\n});\n","path":"code/1531/23T1/env2/src/5.3_catch.test.ts","fileext":"ts"},"5.3_exception1.ts":{"name":"5.3_exception1.ts","content":"import prompt from 'prompt-sync';\nconst promptFn = prompt();\n\nfunction sqrt(x: number) {\n  if (x < 0) {\n    throw new Error('Error Input < 0');\n  }\n  return Math.pow(x, 0.5);\n}\n\nconst input = promptFn('Please enter a number: ');\nconsole.log(sqrt(parseInt(input)));\n","path":"code/1531/23T1/env2/src/5.3_exception1.ts","fileext":"ts"},"5.3_exception2.ts":{"name":"5.3_exception2.ts","content":"import prompt from 'prompt-sync';\nconst promptFn = prompt();\n\nfunction sqrt(x: number) {\n  if (x < 0) {\n    throw new Error('Error Input < 0');\n  }\n  return Math.pow(x, 0.5);\n}\n\ntry {\n  const input = promptFn('Please enter a number: ');\n  console.log(sqrt(parseInt(input)));\n} catch (err) {\n  console.error(`Error when inputting! ${err}`);\n  const input = promptFn('Please enter a number: ');\n  console.log(sqrt(parseInt(input)));\n}\n","path":"code/1531/23T1/env2/src/5.3_exception2.ts","fileext":"ts"},"5.3_exception3.ts":{"name":"5.3_exception3.ts","content":"import prompt from 'prompt-sync';\nconst promptFn = prompt();\n\nfunction sqrt(x: number) {\n  if (x < 0) {\n    throw new Error('Error Input < 0');\n  }\n  return Math.pow(x, 0.5);\n}\n\nlet success = false;\nwhile (!success) {\n  try {\n    const input = promptFn('Please enter a number: ');\n    console.log(sqrt(parseInt(input)));\n    success = true;\n  } catch (err) {\n    console.error(`Error when inputting! ${err}`);\n  }\n}\n","path":"code/1531/23T1/env2/src/5.3_exception3.ts","fileext":"ts"},"5.3_just_crash.ts":{"name":"5.3_just_crash.ts","content":"import prompt from 'prompt-sync';\nconst promptFn = prompt();\n\nfunction sqrt(x: number) {\n  if (x < 0) {\n    console.error('Error Input < 0');\n    process.exit(1);\n  }\n  return Math.pow(x, 0.5);\n}\n\nconst input = promptFn('Please enter a number: ');\nconsole.log(sqrt(parseInt(input)));\n","path":"code/1531/23T1/env2/src/5.3_just_crash.ts","fileext":"ts"},"5.3_sqrt.ts":{"name":"5.3_sqrt.ts","content":"function sqrt(x: number) {\n  if (x < 0) {\n    throw new Error('Error Input < 0');\n  }\n  return Math.pow(x, 0.5);\n}\n\nexport { sqrt };\n","path":"code/1531/23T1/env2/src/5.3_sqrt.ts","fileext":"ts"},"5.3_throw_catch.ts":{"name":"5.3_throw_catch.ts","content":"function sqrt(x: number) {\n  if (x < 0) {\n    throw new Error('Error Input < 0');\n  }\n  return Math.pow(x, 0.5);\n}\n\nif (process.argv.length === 3) {\n  try {\n    console.log(sqrt(parseInt(process.argv[2])));\n    console.log('Never called if error!');\n  } catch (err) {\n    console.error(`Error when inputting! ${err}`);\n  }\n}\n","path":"code/1531/23T1/env2/src/5.3_throw_catch.ts","fileext":"ts"},"5.4_benign.ts":{"name":"5.4_benign.ts","content":"function dateNow() {\n  return new Date().toISOString();\n}\n\nconsole.log(dateNow());\n","path":"code/1531/23T1/env2/src/5.4_benign.ts","fileext":"ts"},"5.4_benign2.ts":{"name":"5.4_benign2.ts","content":"\nfunction loop(count: number, callback: (num: number) => void) {\n  for (let i = 0; i < count; i++) {\n    callback(i);\n  }\n}\n\nloop(5, console.log);\nloop(7, console.log);\n","path":"code/1531/23T1/env2/src/5.4_benign2.ts","fileext":"ts"},"5.4_dry_dirty.ts":{"name":"5.4_dry_dirty.ts","content":"import { argv } from 'process';\n\nif (argv.length !== 3) {\n  process.exit(1);\n}\n\nconst num = parseInt(argv[2], 10);\n\nif (num === 2) {\n  for (let i = 10; i < 20; i++) {\n    const result = Math.pow(i, 2);\n    console.log(`${i} ** 2 = ${result}`);\n  }\n} else if (num === 3) {\n  for (let i = 10; i < 20; i++) {\n    const result = i ** 3;\n    console.log(`${i} ** 3 = ${result}`);\n  }\n} else {\n  process.exit(1);\n}\n","path":"code/1531/23T1/env2/src/5.4_dry_dirty.ts","fileext":"ts"},"7.1_day_to_year.ts":{"name":"7.1_day_to_year.ts","content":"// Given a number of days from\n// January 1st 1970, return the year.\n\nimport { isLeapYear } from './7.1_is_leap_year';\n\nfunction dayToyear(days: number) {\n  let year = 1970;\n\n  while (days > 365) {\n    if (isLeapYear(year)) {\n      if (days > 366) {\n        days -= 366;\n        year += 1;\n      }\n    } else {\n      days -= 365;\n      year += 1;\n    }\n  }\n\n  return year;\n}\n","path":"code/1531/23T1/env2/src/7.1_day_to_year.ts","fileext":"ts"},"7.1_is_leap_year.ts":{"name":"7.1_is_leap_year.ts","content":"export function isLeapYear(year: number) {\n  if (year % 4 !== 0) {\n    return false;\n  } else if (year % 100 !== 0) {\n    return true;\n  } else if (year % 400 !== 0) {\n    return false;\n  } else {\n    return true;\n  }\n}\n","path":"code/1531/23T1/env2/src/7.1_is_leap_year.ts","fileext":"ts"},"8.1_express_error_1.ts":{"name":"8.1_express_error_1.ts","content":"/* eslint-disable no-unreachable */\nimport express from 'express';\n\nconst app = express();\nconst port = 3001;\n\napp.get('/goerror', (req, res) => {\n  throw new Error('Error, oh no!');\n  res.send('Probably won\\'t get this message');\n});\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/23T1/env2/src/8.1_express_error_1.ts","fileext":"ts"},"8.1_express_error_2.test.ts":{"name":"8.1_express_error_2.test.ts","content":"import request from 'sync-request';\r\n\r\ndescribe('Test Apple', () => {\r\n  test('If it returns a name string successfully', () => {\r\n    const res = request(\r\n      'GET',\r\n      'http://localhost:3001/hello',\r\n      {}\r\n    );\r\n    const bodyObj = JSON.parse(String(res.getBody()));\r\n    expect(bodyObj.msg).toBe('Hello there!');\r\n  });\r\n});\n","path":"code/1531/23T1/env2/src/8.1_express_error_2.test.ts","fileext":"ts"},"8.1_express_error_2.ts":{"name":"8.1_express_error_2.ts","content":"/* eslint-disable no-unreachable */\n\nimport express from 'express';\nimport HTTPError from 'http-errors';\nimport errorHandler from 'middleware-http-errors';\n\nconst app = express();\nconst port = 3001;\n\napp.use(express.json());\n\napp.get('/goerror', (req, res) => {\n  throw HTTPError(400, 'Error, oh no!');\n  res.send('Probably won\\'t get this message');\n});\n\napp.get('/hello', (req, res) => {\n  res.json({ msg: 'Hello there!' });\n});\n\napp.use(errorHandler());\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/23T1/env2/src/8.1_express_error_2.ts","fileext":"ts"},"8.1_img_serve.ts":{"name":"8.1_img_serve.ts","content":"import express from 'express';\n\nconst app = express();\nconst port = 3001;\n\napp.use('/static', express.static('static'));\n\napp.listen(port, () => {\n  console.log(`Listening on port ${port}`);\n});\n","path":"code/1531/23T1/env2/src/8.1_img_serve.ts","fileext":"ts"},"8.1_pull_img.ts":{"name":"8.1_pull_img.ts","content":"import request from 'sync-request';\nimport fs from 'fs';\n\nconst res = request(\n  'GET',\n  'http://www.traveller.com.au/content/dam/images/h/1/p/q/1/k/image.related.articleLeadwide.620x349.h1pq27.png/1596176460724.jpg'\n);\nconst body = res.getBody();\nfs.writeFileSync('test.jpg', body, { flag: 'w' });\n","path":"code/1531/23T1/env2/src/8.1_pull_img.ts","fileext":"ts"},"8.1_timeout.ts":{"name":"8.1_timeout.ts","content":"const time = 3;\nconsole.log(`Standup start for ${time} seconds!`);\nfunction finishStandup() {\n  console.log('Standup is now over');\n}\nsetTimeout(finishStandup, time * 1000);\n","path":"code/1531/23T1/env2/src/8.1_timeout.ts","fileext":"ts"},"9.1_auth_fixed.ts":{"name":"9.1_auth_fixed.ts","content":"type Data = {\n  users: { [email: string]: string };\n};\n\nimport { getHashOf } from './9.1_hash';\n\nconst data: Data = {\n  users: {},\n};\n\nfunction register(email: string, pw: string) {\n  if (email in data.users) {\n    return false;\n  } else {\n    data.users[email] = getHashOf(pw);\n    return true;\n  }\n}\n\nfunction login(email: string, pw: string) {\n  if (email in data.users) {\n    if (getHashOf(pw) === data.users[email]) {\n      return true;\n    }\n  }\n  return false;\n}\n","path":"code/1531/23T1/env2/src/9.1_auth_fixed.ts","fileext":"ts"},"9.1_auth_simple.ts":{"name":"9.1_auth_simple.ts","content":"type Data = {\n  users: { [email: string]: string };\n};\n\nconst data: Data = {\n  users: {},\n};\n\nfunction register(email: string, pw: string) {\n  if (email in data.users) {\n    return false;\n  } else {\n    data.users[email] = pw;\n    return true;\n  }\n}\n\nfunction login(email: string, pw: string) {\n  if (email in data.users) {\n    if (pw === data.users[email]) {\n      return true;\n    }\n  }\n  return false;\n}\n","path":"code/1531/23T1/env2/src/9.1_auth_simple.ts","fileext":"ts"},"9.1_hash.ts":{"name":"9.1_hash.ts","content":"import crypto from 'crypto';\n\nfunction getHashOf(plaintext: string) {\n  return crypto.createHash('sha256').update(plaintext).digest('hex');\n}\n\nconst msg = 'BigMacSecretSauce';\nconst hash = getHashOf(msg);\n\nconsole.log(hash);\n\nexport { getHashOf }; // ignore this line\n","path":"code/1531/23T1/env2/src/9.1_hash.ts","fileext":"ts"}}},"__N_SSG":true}