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?

More than 3 years have passed since last update.

Rubyでハナチャン(非破壊配列操作)

Posted at

listmonster.png

出典: Learn You a Haskell for Great Good!

head

array.first

irb(main):005:0> a = [1, 2, 3]
=> [1, 2, 3]
irb(main):007:0> a.first
=> 1
irb(main):008:0> a
=> [1, 2, 3]

tail

array.drop(1)

irb(main):005:0> a = [1, 2, 3]
=> [1, 2, 3]
irb(main):009:0> a.drop(1)
=> [2, 3]
irb(main):010:0> a
=> [1, 2, 3]

init

array[0...-1]

irb(main):010:0> a
=> [1, 2, 3]
irb(main):011:0> a[0...-1]
=> [1, 2]
irb(main):012:0> a
=> [1, 2, 3]

last

array.last

irb(main):013:0> a
=> [1, 2, 3]
irb(main):014:0> a.last
=> 3
irb(main):015:0> a
=> [1, 2, 3]
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?