# Selectperm bug or wrong documentation?

**URL:** https://discourse.julialang.org/t/selectperm-bug-or-wrong-documentation/12852
**Category:** Internals & Design
**Created:** [August 3, 2018, 9:01am UTC](https://discourse.julialang.org/t/selectperm-bug-or-wrong-documentation/12852 "2018-08-03T09:01:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Wikunia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wikunia/32/2180_2.png) [@Wikunia](https://discourse.julialang.org/u/Wikunia)
#### Post date: [August 3, 2018, 9:01am UTC](https://discourse.julialang.org/t/selectperm-bug-or-wrong-documentation/12852/1 "2018-08-03T09:01:51Z")

</div>

I think the behavior of `selectperm` does not fully match the documentation:  
Link to documentation:

> <https://github.com/JuliaLang/julia/blob/release-0.6/base/docs/helpdb/Base.jl#L1231-L1243>

If I have the array `a = [4,3,2,1]` and use `selectperm(a,2)` I can read this part:

> If `k` is a single index (Integer), an array of the first `k` indices is returned;

then the expected behavior is: to get `[4,3]` as `a[[4,3]]` is `[1,2]` but regarding this:

> Also note that this is equivalent to, but more efficient than, calling  
> `sortperm(...)[k]`.

I would suspect to get only a single index (`3`) which is what `selectperm` actually does.

Using it without documentation I assumed to get `[4,3]` but I’m also happy to use `selectperm(a,1:2)`. Anyway the documentation seems to be wrong.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [August 3, 2018, 12:46pm UTC](https://discourse.julialang.org/t/selectperm-bug-or-wrong-documentation/12852/2 "2018-08-03T12:46:30Z")

</div>

Could you file a GitHub issue about this so it doesn’t get lost?

---

<div class="post-metadata">

### Author: ![Wikunia](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wikunia/32/2180_2.png) [@Wikunia](https://discourse.julialang.org/u/Wikunia)
#### Post date: [August 3, 2018, 12:57pm UTC](https://discourse.julialang.org/t/selectperm-bug-or-wrong-documentation/12852/3 "2018-08-03T12:57:31Z")

</div>

Sure I would also do a PR if the behavior is as expected and only the docstring should be changed.

Issue:  
[https://github.com/JuliaLang/julia/issues/28426](https://github.com/JuliaLang/julia/issues/28426)
