Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9912] index(of:) from a subarray returns the index from the original array #52318

Closed
swift-ci opened this issue Feb 12, 2019 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9912
Radar None
Original Reporter coolmark (JIRA User)
Type Bug
Status Closed
Resolution Invalid
Environment

macOS 10.13.6 Xcode 10.1 Swift 4.2.1 / Swift 4.2 leetcode.com

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 5c598e7de23d1e53e35af4dbdd1cd08e

Issue Description:

Steps :

  1. Create a subarray

  2. Find the index of an item from the subarray

Problem :

  • It is returning the index from the original array.

    var originalArray = [1, 2, 3, 4, 5, 6, 7]
    print("original array : \(originalArray)")
    let indexA = originalArray.index(of: 5)!
    print("index of #​5 : \(indexA)")
    let subArray = originalArray[3 ..< originalArray.count]
    print("subarray : \(subArray)")
    let indexB = subArray.index(of: 5)!
    print("index of #&#8203;5 : \(indexB)")
    // output
    original array : [1, 2, 3, 4, 5, 6, 7]
    index of #&#8203;5 : 4
    subarray : [4, 5, 6, 7]
    index of #&#8203;5 : 4
  • The last index should be 1 not 4.

@theblixguy
Copy link
Collaborator

@swift-ci
Copy link
Collaborator Author

Comment by Joong Seok Lee (JIRA)

Thank you for help. I closed the issue.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants