Get Full Access

Unique

/**
 * Returns a new array containing only the first occurrence of each
 * unique string from the input array, preserving the original order.
 *
 * @param {string[]} strings - An array of strings.
 * @returns {string[]} An array of unique strings.
 */
function unique(strings) {
  const uniqueStrings = {};

  for (const string of strings) {
    if (!uniqueStrings[string]) {
      uniqueStrings[string] = true;
    }
  }

  return Object.keys(uniqueStrings);
}