v1
9/15/2020 by stefan4trivia -00
Setup HTML - click to add setup HTML
disable setup JavaScript
Setup JavaScript
const numbers = [...Array(1000).keys()];
delete caserun single casemove downdrag and drop case


ready



for (const number of numbers) {
	let unit = 32;
	const result = new Array(Math.floor(number / unit)).fill(unit);
	while (unit >= 1) {
		unit /= 2;
		if (number & unit) result.push(unit);
	}
}
delete caserun single casemove upmove downdrag and drop case


ready



for (const number of numbers) {
	const bits = 5;
	let unit = 1 << bits;
	const result = new Array(number >> bits).fill(unit);
	while (unit >= 1) {
		unit >>= 1;
		if (number & unit) result.push(unit);
	}
}
delete caserun single casemove upmove downdrag and drop case


ready



for (const number of numbers) {
	const maxUnit = 32;
	const prefixLength = Math.floor(number / maxUnit);
    // precalculate the length of the result array
	let length = prefixLength, unit = maxUnit;
	while (unit >= 1) {
		unit /= 2;
		if (number & unit) length++;
	}
	// allocate and fill array
	const result = new Array(length).fill(maxUnit);
	let i = prefixLength; unit = maxUnit;
	while (unit >= 1) {
		unit /= 2;
		if (number & unit) result[i++] = unit;
	}
}
delete caserun single casemove upmove downdrag and drop case


ready



for (const number of numbers) {
	const bits = 5, maxUnit = 1 << bits;
	const prefixLength = number >> bits;
    // precalculate the length of the result array
	let length = prefixLength, unit = maxUnit;
	while (unit >= 1) {
		unit >>= 1;
		if (number & unit) length++;
	}
	// allocate and fill array
	const result = new Array(length).fill(maxUnit);
	let i = prefixLength; unit = maxUnit;
	while (unit >= 1) {
		unit >>= 1;
		if (number & unit) result[i++] = unit;
	}
}
delete caserun single casemove updrag and drop case


ready



for (number of numbers) {
	let unit = 32;
	const result = []
	while (unit > 0) {
		while (number >= unit) {
			result.push(unit);
			number -= unit;
		}
		unit >>= 1;
	}
}
Test Case - click to add another test case
Teardown JS - click to add teardown JavaScript
Output (DOM) - click to monitor output (DOM) while test is running
RUN