Skip to content
Anthropic

Claude Sonnet 5.5Code and bug fixes

Anthropic's model for everyday development: new features, finding bugs, code review. Reads PDFs and screenshots

Claude Sonnet 5.5

Price shown before you run · One-time payment, no auto-renewal

Claude Sonnet 5.5

Why does [1, 10, 2].sort() in JavaScript return [1, 10, 2] instead of [1, 2, 10]? How do I fix it? Keep it short.

Reasons before answering

Array.prototype.sort() converts elements to strings by default and compares them lexicographically (by UTF-16 code units). As strings, "10" comes before "2" because "1" < "2", so the order is 1, 10, 2.

Fix: pass a comparator function:

[1, 10, 2].sort((a, b) => a - b); // [1, 2, 10]

For descending order, use (a, b) => b - a.

Note that sort() mutates the original array. If you want to keep it intact, use [...arr].sort(...) or arr.toSorted((a, b) => a - b) in newer environments.

Message Claude Sonnet 5.5...

Sonnet at work

A new feature and a security review

New feature

Write a typed debounce function in TypeScript with a short example for a search field.

Typed debounce in TypeScript

Implementation

type DebouncedFunction<Args extends unknown[]> = {
  (...args: Args): void;
  cancel(): void;
  flush(): void;
};

function debounce<Args extends unknown[]>(
  fn: (...args: Args) => void,
  delay: number
): DebouncedFunction<Args> {
  let timeoutId: ReturnType<typeof setTimeout> | undefined;
  let lastArgs: Args | undefined;

  const debounced = (...args: Args): void => {
    lastArgs = args;
    if (timeoutId !== undefined) clearTimeout(timeoutId);

    timeoutId = setTimeout(() => {
      timeoutId = undefined;
      fn(...args);
      lastArgs = undefined;
    }, delay);
  };

  debounced.cancel = (): void => {
    if (timeoutId !== undefined) clearTimeout(timeoutId);
    timeoutId = undefined;
    lastArgs = undefined;
  };
Ask the same
Code review

What is dangerous about the query SELECT * FROM users WHERE name = '" + input + "'? Explain the risk and show a safe version.

The Danger: SQL Injection

The query is built by concatenating user input directly into the SQL string. The database can't distinguish between the query's intended structure and data supplied by the user, so an attacker can inject their own SQL.

Example attack

If the code is something like:

query = "SELECT * FROM users WHERE name = '" + input + "'"

and the user enters:

' OR '1'='1

The resulting query becomes:

SELECT * FROM users WHERE name = '' OR '1'='1'

Since '1'='1' is always true, this returns every row in the table.

Worse possibilities

Ask the same

Contracts and reports

  • Upload a PDF or a document - the model reads it and answers from the text
  • A short summary, key numbers and dates
  • Compares two versions and shows what changed
  • Try Claude Sonnet 5.5

How to use Claude Sonnet 5.5

  1. 1Write a questionA task, text or code. Attach a file or a photo if needed
  2. 2Check the priceThe request price is on the button before you send
  3. 3Get the answerAsk to rewrite, refine or keep the conversation going

Sonnet at a glance

  • 1MContext tokens: long chats and big files
  • PhotosUnderstands images and screenshots
  • PDFReads documents
  • SearchWeb search on a toggle
  • ≈ 1.5 tokensPrice of one run

How much it costs

per typical answer (1,500 input and 700 output model tokens)
≈ 1.5 tokens

The exact price is on the button before you run it

Try Claude Sonnet 5.5

Questions about Claude Sonnet 5.5

When should I choose Sonnet 5.5 over Opus 5.5?

When the task is clearly scoped: adding a feature, fixing a bug, or improving a single module. Opus is positioned for larger, interconnected changes.

Can I give Sonnet code alongside a PDF?

Yes. The model reads files and PDFs and supports up to 1,000,000 tokens of context. Specify which documents define requirements and which are reference material.

Helpful guides

Guides and explainers from our blog

All articles
All articles

Try Claude Sonnet 5.5

Try for free