LoginSignup
2
1

More than 1 year has passed since last update.

paizaの問題集でforEach文を利用しました

process.stdin.resume();
process.stdin.setEncoding('utf8');
// 自分の得意な言語で
// Let's チャレンジ!!
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  //入力した文字列をsplitメソッドを使って分割
  const array1 = lines[0].split(' ');
  // forEach文を使用して各要素をそれぞれ標準出力する
  array1.forEach(function(element){
      console.log(element);
  });
});

forEach文は

[配列名].forEach(function(変数) {
     //処理文
});

で記述します。

2
1
0

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
2
1