Data Types - Exercise 3

Question 1: Add Large Integers

Convert both integer strings to BigInt, add them, and return the result as a string.

Expected output: "9007199254741000" (print this with console.log)

javascript

function addLargeIntegers(left, right) {
  // Write your solution here
}

console.log(addLargeIntegers("9007199254740993", "7"));

Question 2: Double a Big Integer

Convert the integer string to BigInt, multiply by 2n, and return the result as a string.

Expected output: "24691357802469135780" (print this with console.log)

javascript

function doubleBigInteger(text) {
  // Write your solution here
}

console.log(doubleBigInteger("12345678901234567890"));

Question 3: Count Array Entries

Return the number of items in the supplied array.

Expected output: 3 (print this with console.log)

javascript

function countArrayEntries(items) {
  // Write your solution here
}

console.log(countArrayEntries(["red","blue","green"]));

Question 4: Build an Array Pair

Return an array containing the two supplied values in their original order.

Expected output: ["north","south"] (print this with console.log)

javascript

function buildArrayPair(first, second) {
  // Write your solution here
}

console.log(buildArrayPair("north", "south"));

Question 5: Classify Object Values

Return "reference" for non-null objects and functions; return "primitive" for all other values.

Expected output: "reference" (print this with console.log)

javascript

function classifyReference(value) {
  // Write your solution here
}

console.log(classifyReference([1]));

Question 6: Compare Null's typeof

Return an array containing typeof null followed by typeof the supplied value.

Expected output: ["object","number"] (print this with console.log)

javascript

function typeOfNullValue(value) {
  // Write your solution here
}

console.log(typeOfNullValue(3));

Question 7: Detect an Invalid Conversion

Convert the supplied text to a number and return whether the result is NaN.

Expected output: true (print this with console.log)

javascript

function invalidNumberText(text) {
  // Write your solution here
}

console.log(invalidNumberText("pear"));

Question 8: Avoid NaN Coercion

Return an array with Number.isNaN applied to the supplied value, followed by Number.isNaN applied after converting it with Number.

Expected output: [false,true] (print this with console.log)

javascript

function isActualNaN(value) {
  // Write your solution here
}

console.log(isActualNaN("pear"));

Question 9: Check a Finite Number

Return true only if the supplied value is a finite number, without converting it.

Expected output: false (print this with console.log)

javascript

function isFiniteValue(value) {
  // Write your solution here
}

console.log(isFiniteValue("10"));

Question 10: Detect an Array Instance

Return whether the supplied value is an instance of Array.

Expected output: true (print this with console.log)

javascript

function isArrayInstance(value) {
  // Write your solution here
}

console.log(isArrayInstance([2,4]));