Set - Exercise 3

Question 1: Count Unique Words Ignoring Case

Return the number of distinct words after converting each to lowercase.

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

javascript

function countCaseInsensitiveSetWords(words) {
  // Write your solution here
}

console.log(countCaseInsensitiveSetWords(["Cat","cat","DOG"]));

Question 2: Keep First Unique Names Ignoring Case

Return the first spelling of each name, treating names as equal after lowercasing.

Expected output: ["Ada","Bo"] (print this with console.log)

javascript

function firstCaseInsensitiveNames(names) {
  // Write your solution here
}

console.log(firstCaseInsensitiveNames(["Ada","ada","Bo"]));

Question 3: Remove Repeated IDs

Return the input records whose id occurs for the first time, preserving their order.

Expected output: [{"id":1,"name":"A"},{"id":2,"name":"C"}] (print this with console.log)

javascript

function firstRecordForEachId(records) {
  // Write your solution here
}

console.log(firstRecordForEachId([{"id":1,"name":"A"},{"id":1,"name":"B"},{"id":2,"name":"C"}]));

Question 4: Find Repeated Values Once

Return each value that occurs more than once, ordered by when it is first repeated, without duplicates.

Expected output: [2,1] (print this with console.log)

javascript

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

console.log(repeatedSetValuesOnce([1,2,2,1,2]));

Question 5: Check Whether Values Are Unique

Return true if no value appears more than once in the array.

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

javascript

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

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

Question 6: Count Unique Array Keys

Return the number of distinct id values in the supplied objects.

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

javascript

function countUniqueObjectIds(records) {
  // Write your solution here
}

console.log(countUniqueObjectIds([{"id":1},{"id":1},{"id":2}]));

Question 7: Preserve Set Reinsert Order

Create a Set from the values, delete the supplied value, add it again, and return the resulting insertion order.

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

javascript

function reinsertSetValue(values, value) {
  // Write your solution here
}

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

Question 8: Return Common Unique Letters

Return distinct ASCII characters from the first string that occur in the second, in their first-string order.

Expected output: ["a"] (print this with console.log)

javascript

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

console.log(commonUniqueAsciiLetters("banana", "apple"));

Question 9: Track Set Size after Adds

Start with an empty Set. Add each input value and return an array containing the size after each addition.

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

javascript

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

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

Question 10: Return Set Deletion Results

Create a Set from initial values. Delete each requested value in order and return the booleans from delete.

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

javascript

function setDeletionResults(initial, requested) {
  // Write your solution here
}

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