Categories

Sorted Unique

Remove duplicates from a sorted array using lodash _.sortedUniq

Remove consecutive duplicates from a sorted JSON array.

Highlights:

  • Uses lodash _.sortedUniq
  • Works on sorted arrays
  • Returns the unique values as JSON

Example:

  • Array: [1, 1, 2, 2, 3]
  • Result: [1, 2, 3]

Enter a JSON array

Key Facts

Category
Data Processing
Input Types
textarea
Output Type
text
Sample Coverage
4
API Ready
Yes

Overview

The Sorted Unique tool efficiently removes consecutive duplicate values from a sorted JSON array using the lodash _.sortedUniq function. It ensures your data is clean and unique, ideal for preprocessing sorted datasets.

When to Use

  • When you have a pre-sorted array and need to eliminate duplicate entries.
  • To optimize data storage by removing redundant values in sorted lists.
  • Before performing operations that require unique elements, such as set operations or analysis.

How It Works

  • Input a JSON array that is already sorted in ascending order.
  • The tool applies the lodash _.sortedUniq function to identify and remove consecutive duplicates.
  • It returns a new JSON array containing only the unique values in their original order.

Use Cases

Cleaning sorted log files to remove repeated entries.
Preparing sorted lists of IDs or codes for database operations.
Optimizing sorted arrays in data pipelines to reduce memory usage.

Examples

1. Remove Duplicates from Sorted Timestamps

Data Analyst
Background
You have a sorted list of event timestamps from a log file, but some events are logged multiple times consecutively.
Problem
The array has duplicate timestamps that need to be removed for accurate analysis.
How to Use
Enter the sorted JSON array of timestamps into the tool's input field.
Outcome
The tool returns a new array with consecutive duplicate timestamps removed, e.g., [1625097600, 1625097601, 1625097603].

2. Deduplicate Sorted Product Codes

Inventory Manager
Background
You have a sorted list of product codes from an inventory scan, but some codes appear multiple times in a row due to scanning errors.
Problem
Need to clean the list to get unique product codes for stock reconciliation.
How to Use
Paste the sorted array of product codes into the tool.
Outcome
A unique list of product codes is generated, such as ['A001', 'A002', 'B001'].

Try with Samples

json, video

Related Hubs

FAQ

What does the Sorted Unique tool do?

It removes consecutive duplicate values from a sorted JSON array using lodash _.sortedUniq.

Does the array need to be sorted?

Yes, the tool requires the input array to be sorted for _.sortedUniq to work correctly.

What input format is accepted?

You must provide a valid JSON array, such as [1, 1, 2, 3].

Can it handle non-numeric data?

Yes, it works with any data type that can be compared, as long as the array is sorted.

Is the original array modified?

No, the tool returns a new array with duplicates removed, leaving the input unchanged.

API Documentation

Request Endpoint

POST /en/api/tools/sorted-unique

Request Parameters

Parameter Name Type Required Description
array textarea Yes Enter a JSON array

Response Format

{
  "result": "Processed text content",
  "error": "Error message (optional)",
  "message": "Notification message (optional)",
  "metadata": {
    "key": "value"
  }
}
Text: Text

AI MCP Documentation

Add this tool to your MCP server configuration:

{
  "mcpServers": {
    "elysiatools-sorted-unique": {
      "name": "sorted-unique",
      "description": "Remove duplicates from a sorted array using lodash _.sortedUniq",
      "baseUrl": "https://elysiatools.com/mcp/sse?toolId=sorted-unique",
      "command": "",
      "args": [],
      "env": {},
      "isActive": true,
      "type": "sse"
    }
  }
}

You can chain multiple tools, e.g.: `https://elysiatools.com/mcp/sse?toolId=png-to-webp,jpg-to-webp,gif-to-webp`, max 20 tools.

If you encounter any issues, please contact us at [email protected]