DEV Community

loading...

Discussion on: Daily Challenge #256 - How Many Are Smaller Than I?

Collapse
aminnairi profile image
Amin • Edited

TypeScript

const smaller = (items: number[]): Uint32Array => {
    const length: number = items.length;
    const output: Uint32Array = new Uint32Array(length);

    for (let current: number = 0; current < length; current++) {
        output[current] = 0;

        for (let next: number = current + 1; next < length; next++) {
            if (items[next] < items[current]) {
                output[current]++;
            }
        }
    }

    return output;
};