Data Types - Exercise 4

Question 1: Count Falsy Entries

Return the number of falsy values in the supplied array.

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

javascript

function countFalsyEntries(values) {
  // Write your solution here
}

console.log(countFalsyEntries([0,"","0",null,true]));

Question 2: Keep Truthy Entries

Return a new array containing only the truthy values, in their original order.

Expected output: ["yes",9] (print this with console.log)

javascript

function keepTruthyEntries(values) {
  // Write your solution here
}

console.log(keepTruthyEntries([0,"yes",false,9]));

Question 3: Format an Invoice Number

Convert the supplied number to a string prefixed with "Invoice #".

Expected output: "Invoice #57" (print this with console.log)

javascript

function formatInvoiceNumber(number) {
  // Write your solution here
}

console.log(formatInvoiceNumber(57));

Question 4: Format a Boolean Setting

Convert the supplied boolean to a string prefixed with "enabled: ".

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

javascript

function formatBooleanSetting(enabled) {
  // Write your solution here
}

console.log(formatBooleanSetting(false));

Question 5: Convert Empty Text

Convert the supplied string with Number and return the resulting number.

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

javascript

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

console.log(numberFromEmptyText(""));

Question 6: Convert an Array to Text

Use String to convert the supplied array and return the resulting text.

Expected output: "1,2,3" (print this with console.log)

javascript

function arrayAsText(values) {
  // Write your solution here
}

console.log(arrayAsText([1,2,3]));

Question 7: Convert Text to Boolean

Return the Boolean conversion of the supplied text.

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

javascript

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

console.log(textAsBoolean("false"));

Question 8: Check Array Values

Return true if the supplied value is an array and false otherwise.

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

javascript

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

console.log(checkArrayValue({"length":2}));

Question 9: Distinguish Collections

Return "array" for arrays, "object" for other non-null objects, and "other" otherwise.

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

javascript

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

console.log(collectionKind({"item":1}));

Question 10: Copy a Record

Return a shallow copy of the supplied object with an additional saved property set to true.

Expected output: {"id":8,"saved":true} (print this with console.log)

javascript

function copySavedRecord(record) {
  // Write your solution here
}

console.log(copySavedRecord({"id":8}));