4
0

「paizaxQiita記事投稿キャンペーン」より、Dランク問題「N倍の文字列」を解きます。

言語はJavaScriptです。

for文を使用

回数分回して*を文字列追加しています。

let str = '';
for (let i = 0; i < lines[0]; i++) {
    str += '*';
}
console.log(str);

Arrayオブジェクトを使用

console.log(Array(+lines[0]).fill('*').join(''));

個数分の空配列作って、それを文字列*で満たし文字連結させます。

4
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0