deno.land / x / masx200_leetcode_test@10.6.5 / rearrange-spaces-between-words / index.ts
123456789101112131415161718// deno-lint-ignore-file ban-ts-commentexport default function reorderSpaces(text: string): string { const words = text.split(/\s+/g).filter(Boolean);
//@ts-ignore const spaces = Array.prototype.reduce.call( text, //@ts-ignore (a, v) => a + Number(v === " "), 0, ) as number;
if (words.length <= 1) return words.join("") + " ".repeat(spaces); const sep = " ".repeat(Math.floor(spaces / (words.length - 1)));
return words.join(sep) + " ".repeat(spaces % (words.length - 1));}
Version Info