# Question about sort by type

**URL:** <https://discourse.codecombat.com/t/question-about-sort-by-type/3577>\
**Category:** Uncategorized\
**Created:** [April 17, 2015, 3:24am UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577 "2015-04-17T03:24:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [April 17, 2015, 3:24am UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577/1 "2015-04-17T03:24:30Z")

</div>

In the level the Two Flowers I wanted to command my soldiers with a function but the peasant is also a friend so is there a way to filter the peasant out of the array since I do not know the place in the array(otherwise I would manually remove it)

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [April 17, 2015, 3:37am UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577/2 "2015-04-17T03:37:53Z")

</div>

hector is a different type than your soldiers

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [April 18, 2015, 3:03am UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577/3 "2015-04-18T03:03:01Z")

</div>

I know that I want to know how to remove him from the array

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [April 18, 2015, 8:31am UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577/4 "2015-04-18T08:31:50Z")

</div>

1. If you are using find friends why do you want to run over the array twice, once to remove hector and once to tell your soldiers what to do. (which was what my answer is saying: hector is of a different type . . . so ignore type of hector and do what ever with the rest.)

2. If you only have one type of soldier use the find by type “soldier”. then hector is never in the array.  
If you have more than one type of soldier, there is a good chance you are telling them to do different things based on type so either go back to #1, or put each type into a different array, and there again, no hector.

3. You never say what language you are using so don’t really want to know a (specific language) coding answer, and yet you reject the general case non-coding answer.

---

<div class="post-metadata">

**Author:** ![VincentMaths](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vincentmaths/32/2418_2.png) [@VincentMaths](https://discourse.codecombat.com/u/VincentMaths)\
**Post date:** [April 18, 2015, 8:40am UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577/5 "2015-04-18T08:40:32Z")

</div>

A [“building from scratch” structure](http://discourse.codecombat.com/t/priority-targeting/3487/2)

A [removing from array approach](http://stackoverflow.com/questions/5767325/remove-specific-element-from-an-array)

(baby in my arms, can’t write much)

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [April 19, 2015, 12:15am UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577/6 "2015-04-19T00:15:41Z")

</div>

> [@Vlevo](#):
>
> 1. You never say what language you are using so don’t really want to know a (specific language) coding answer, and yet you reject the general case non-coding answer.

Okay then I want to know how to remove hector from the array in JS

---

<div class="post-metadata">

**Author:** ![Vlevo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/vlevo/32/2074_2.png) [@Vlevo](https://discourse.codecombat.com/u/Vlevo)\
**Post date:** [April 19, 2015, 12:26am UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577/7 "2015-04-19T00:26:44Z")

</div>

Google: javascript remove from array

looks like you want to pretend the array is a piece of movie film and splice that bad boy right out of the picture.

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [April 20, 2015, 2:23am UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577/8 "2015-04-20T02:23:41Z")

</div>

> [@Vlevo](#):
>
> looks like you want to pretend the array is a piece of movie film and splice that bad boy right out of the picture.

To tell you the truth I kinda want to

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [April 20, 2015, 2:31am UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577/9 "2015-04-20T02:31:37Z")

</div>

> [@Vlevo](#):
>
> javascript remove from array

Okay thank you Vlevo

**for refs**

I used the following command to remove the first element knowing that hector will always be first

```python
friends.splice(0, 1);

```

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [April 20, 2015, 8:13pm UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577/10 "2015-04-20T20:13:30Z")

</div>

Does it actually work? There are some bugs around API protection that might be messing that up in some cases, where you can’t always modify an array that you get as a return value from a function.

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [April 21, 2015, 2:51am UTC](https://discourse.codecombat.com/t/question-about-sort-by-type/3577/11 "2015-04-21T02:51:02Z")

</div>

Well it worked without error for me
