Comment

Comment by khuey

You should try writing it out. Doing it without introducing another unpredictable branch is harder than it looks.

I discussed this with a coworker earlier this week and the best they were able to come up with was

    for &x in input {
        out.push(x);
        n += (x > threshold) as usize;
        out.truncate(n);
    }
which works but is ugly af imo.
parent khuey 2 months ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton