Question: I'm new to programming, so my following question will probably look rather easy to answer for most of you. Here we go:

1. I have an array of strings with predefined content.
2. I ask the user for some input.
3. I'd like to see if the input is identical to one of the elements of the array. 
3a. If there is a match, I'd like to print out in which "block" of the array it was.
3b. If there is no match, I'd like to notify the user that there was no match.

So far, I managed to get until point 3a but not further. Please could you give me a suggestion?
Here is my code(let) so far:

```
string fixed_array[4] = {"apple", "orange", "banana", "kiwi"};
cout << "Please enter something:\n";
string user_input;
cin >> user_input;
for (int i=0; i!=4; i++) {
    if (user_input == fixed_array[i]) {cout << "Fruit is in " << i << "\n";}

```

Unfortunately I don't know how to inform the user if the requested fruit is not in the array, as if I add 'else' after 'if', the program will naturally write out the 'not found' message each time there is a mismatch with an array element.

I was thinking of an exit signal for the loop (bool maybe?): if there is a match within the loop: true, if no match: false. Then use this bool in a simple 'if' statement to print out the 'not found' message.

Is it possible to do it this way, or am I completely off course?

Thanks in advance!

Answer: 
maybe something like this ? 

```
array = [1,2,3,4,5,6,7]
rejected = array.map { |a| array.delete(a) if  a.even? }.compact

```
I don't know if there's a built-in method that does this. [`Array#reject!`](http://ruby-doc.org/core-2.3.1/Array.html#method-i-reject-21) and [`Array#delete_if`](http://ruby-doc.org/core-2.3.1/Array.html#method-i-delete_if) modify the array but do not return the rejected elements. So here's a custom method that does what you request:

```
def rej_method(arr, n)
  a = arr - arr.reject {|i| i==n }
  arr.delete(n)
  a
end

```

Then as per your example:

```
array = [1, 2]
rejected_elements = rej_method(array, 1)
rejected_elements #=> [1]
array             #=> [2]

```

---

Consider using the [`Enumerable#partition`](http://ruby-doc.org/core-2.3.1/Enumerable.html#method-i-partition) method, example:

```
arr =  [1, 2, 3, 4, 5] 
arr.partition {|i| i==1 } #=> [[1], [2, 3, 4, 5]] 

```