Welcome to your second assignment in Full-Stack Development!
You’ll take what you learned from JavaScript and now write safer, cleaner, and more reliable code with TypeScript.
Make sure you have Node.js (v18 or newer) and TypeScript installed.
Check your Node version:
node -vInstall TypeScript globally (only once):
npm install -g typescriptTo compile a TypeScript file:
tsc Problem1.tsRun the compiled JavaScript file:
node Problem1.jsOr, if you prefer one command:
npx ts-node Problem1.tstypescript-assignment-2/
├── Problem1.ts
├── Problem2.ts
├── Problem3.ts
├── Problem4.ts
├── Problem5.ts
└── Problem6.ts
Each problem file is stand-alone — no imports, no exports, no frameworks.
Open them in VS Code, write your solution inside the given function, and test using the console.log examples.
Write a function that takes two numbers, converts them to strings, and concatenates them.
concatNumbers(4, 5); // "45"
concatNumbers(5, -9); // "5-9"Given two arrays (names and ages), return an array of student objects.
[
{ name: "Joe", age: 50 },
{ name: "Schmo", age: 60 }
]Given a Professor object containing classes and students,
return all unique student names sorted by age (ascending).
Given an array of Student or Athlete objects,
return a new array where all become Athletes.
Existing athletes keep their original sport; new ones get the default sport you provide.
Write a generic function that counts how many times a value appears in an array.
countOccurrences([2, 4, 6, 6, 8], 6); // 2
countOccurrences([true, true, true], false); // 0Given a possibly incomplete user object, return either:
- the user itself (if all properties exist), or
- an array of missing property names.
Also handle null or undefined safely.
Every file already includes small example tests at the bottom like:
console.log(concatNumbers(4, 5));Run each one manually:
npx ts-node Problem1.tsNo external testing libraries needed.
- Always give explicit parameter and return types.
- Use
typealiases to define object shapes. - Use
?for optional properties. - Use union (
|) and intersection (&) types when combining data. - Experiment with type narrowing using
typeof.
By completing this assignment, you should be able to:
✔️ Understand how TypeScript checks types at compile-time ✔️ Define and reuse custom types ✔️ Work safely with optional data ✔️ Create generic and reusable functions ✔️ Write JavaScript code that’s more predictable and self-documenting
When finished, push your completed .ts files to your GitHub Classroom repository.
Ensure all files compile cleanly (no red squiggles or compiler errors) before submitting.