Looking for FIT2102 Programming paradigms - S2 2025 test answers and solutions? Browse our comprehensive collection of verified answers for FIT2102 Programming paradigms - S2 2025 at learning.monash.edu.
Get instant access to accurate answers and detailed explanations for your course questions. Our community-driven platform helps students succeed!
What is the output of the following JavaScript code snippet?
const result = [1, 2, 3, 4, 5, 6]
.map(x => x + 1)
.filter(x => x % 3 === 0)
.reduce((acc, x) => acc + x, 5);
console.log(result);
Which of the following best describes the “Referential Transparency” property?
Given the following function:
function add(x) {
return y => y + x;
}
What term describes the mechanism that allows the inner anonymous function (y => y + x) to access the x variable from its containing add function, even after add has finished executing?
Given the TypeScript interface below, which of the following object literals is a correctly typed Student object?
interface Student {
id: number;
name: string;
major?: string;
}
What is the primary benefit of using generics in TypeScript, such as in `function binarySearch2<T>(arr: T[], key: T): number`?
Fill in the blank to make the code calculate the sum of the cubes of the numbers from 1 to 3 (i.e., 1³ + 2³ + 3³).
function sumTo(n, f = x => x) {
return n ? f(n) + sumTo(n-1, f) : 0;
}
const sumOfCubes = sumTo(3, _______________);
// sumOfCubes should be 36 (1 + 8 + 27)
Given the following code: `const myObj = { a: 1 };`. Which of the following statements accurately describes the immutability of `myObj`?
What is the value of totalLength after this code from a course exercise is executed?
const words = ["apple", "banana", "cherry"];
const totalLength = words
.map(word => word.length)
.reduce((sum, length) => sum + length, 0);
A developer is writing a TypeScript function setLeftPadding that should accept a value parameter that can be either a string (e.g., `"100px"`) or a number (e.g., `100`). Which TypeScript feature should be used to precisely model this requirement in the function's type annotation?
What is the primary advantage of using TypeScript over plain JavaScript for developing large, complex applications?