0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ruby eachとmapの違い

Posted at

mapは既存の配列に情報を加工したいとき、eachは計算如何によっては新しい配列に情報を格納することがある場合とで使い分けられる

def validEmailList(emailList)
  arr=[]
  def isEmailValid(email)
      count = email.count("@")
      strIndex = email.index("@")
      slice = email.slice(strIndex..-1)
      if email.include?(" ") || count > 1 || strIndex == 0 || !slice.include?(".")
          return false
      else
          return true
      end
  end

  emailList.each{ |email|
      if isEmailValid(email)
          arr << email
      else
          puts "no"
      end
  }
  return arr

end
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?