Sha256: fb77e8b2f23bcac1beb5cb7faae68a2b6b3c11b87bebed6735edd377bc69e465

Contents?: true

Size: 717 Bytes

Versions: 15

Compression:

Stored size: 717 Bytes

Contents

describe "Array#index" do
  it "returns the index of the first element == to object" do
    [1, 2, 3, 4, 5, 6].index(3).should == 2
    [1, 2, 3, 4, 5, 6].index(4).should == 3
  end

  it "returns 0 if first element == to object" do
    [2, 1, 3, 2, 5].index(2).should == 0
  end

  it "returns size-1 if only last element == to object" do
    [2, 1, 3, 1, 5].index(5).should == 4
  end

  it "returns nil if no element == to object" do
    [2, 1, 1, 1, 1].index(3).should == nil
  end

  it "accepts a block instead of an argument" do
    [4, 2, 1, 5, 1, 3].index { |x| x < 2 }.should == 2
  end

  it "ignores the block if there is an argument" do
    [4, 2, 1, 5, 1, 3].index(5) { |x| x < 2 }.should == 3
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
opal-0.3.41 spec/core/array/index_spec.rb
opal-0.3.40 spec/core/array/index_spec.rb
opal-0.3.39 spec/core/array/index_spec.rb
opal-0.3.38 spec/core/array/index_spec.rb
opal-0.3.37 spec/core/array/index_spec.rb
opal-0.3.36 spec/core/array/index_spec.rb
opal-0.3.35 spec/core/array/index_spec.rb
opal-0.3.34 spec/core/array/index_spec.rb
opal-0.3.33 spec/core/array/index_spec.rb
opal-0.3.32 spec/core/array/index_spec.rb
opal-0.3.31 spec/core/array/index_spec.rb
opal-0.3.30 spec/core/array/index_spec.rb
opal-0.3.29 spec/core/array/index_spec.rb
opal-0.3.28 spec/core/array/index_spec.rb
opal-0.3.27 spec/core/array/index_spec.rb