deno.land / x / masx200_leetcode_test@10.6.5 / rearrange-spaces-between-words / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 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));}
masx200_leetcode_test

Version Info

Tagged at
a year ago