TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

SHOW HN: Left-Pad could be the next FizzBuzz so we coded it up in 13 Languages

4 点作者 fahimulhaq大约 9 年前

1 comment

plugnburn大约 9 年前
14 lines in JS? O&#x27;rly?<p>Even with such a strict check of the padding character length (with an exception) and a period by default it&#x27;s a four-liner at most.<p><pre><code> leftPad = (str, len, pd = &#x27;.&#x27;) =&gt; { if(pd.length !== 1) throw &#x27;Invalid input&#x27; else return Array(len &gt; str.length ? 1+len-str.length : 0).join(pd) + str }</code></pre>