Most languages have a `split` function that lets you turn a string like `“hello world”` into an array like`[“hello”, “world”]`. But what if we don't want to lose the separator? Something like `[“hello”, “ world”]`.

#### Task:

Your job is to implement a function, (`split_without_loss` in Ruby/Crystal, and `splitWithoutLoss` in JavaScript/CoffeeScript), that takes two arguments, `str` (`s` in Python), and `split_p`, and returns the string, split by `split_p`, but with the separator intact. There will be one '|' marker in `split_p`. `str` or `s` will never have a '|' in it. All the text before the marker is moved to the first string of the split, while all the text that is after it is moved to the second one. **Empty strings must be removed from the output, and the input should NOT be modified.**

When tests such as `(str = "aaaa", split_p = "|aa")` are entered, do not split the string on overlapping regions. For this example, return `["aa", "aa"]`, not `["aa", "aa", "aa"]`.

#### Examples (see example test cases for more):

```python
split_without_loss("hello world!", " |") #=> ["hello ", "world!"]
split_without_loss("hello world!", "o|rl") #=> ["hello wo", "rld!"]
split_without_loss("hello world!", "h|ello world!") #=> ["h", "ello world!"]
split_without_loss("hello world! hello world!", " |")
                  #=> ["hello ", "world! ", "hello ", "world!"]
split_without_loss("hello world! hello world!", "o|rl")
                  #=> ["hello wo", "rld! hello wo", "rld!"]
split_without_loss("hello  hello  hello", " | ")
                  #=> ["hello ", " hello ", " hello"]
split_without_loss(" hello world", " |")
                  #=> [" ", "hello ", "world"]
split_without_loss("  hello hello hello", " |")
                  #=> [" ", " ", "hello ", "hello ", "hello"]
split_without_loss("  hello hello hello  ", " |")
                  #=> [" ", " ", "hello ", "hello ", "hello ", " "]
split_without_loss("  hello hello hello", "| ")
                  #=> [" ", " hello", " hello", " hello"]
```

Also check out my other creations — [Identify Case](https://www.codewars.com/kata/identify-case), [Adding Fractions](https://www.codewars.com/kata/adding-fractions),
[Random Integers](https://www.codewars.com/kata/random-integers), [Implement String#transpose](https://www.codewars.com/kata/implement-string-number-transpose), [Implement Array#transpose!](https://www.codewars.com/kata/implement-array-number-transpose), [Arrays and Procs #1](https://www.codewars.com/kata/arrays-and-procs-number-1), and [Arrays and Procs #2](https://www.codewars.com/kata/arrays-and-procs-number-2)

If you notice any issues/bugs/missing test cases whatsoever, do not hesitate to report an issue or suggestion. Enjoy!

Difficulty: EASY
Starter code: def split_without_loss(s, split_p):
	

Solutions:
def split_without_loss(s, split_p):
	return [i for i in s.replace(split_p.replace('|', ''), split_p).split('|') if i]


import re

def split_without_loss(s, m):
	(r, iM) = (m.replace('|', ''), m.index('|'))
	(out, i, j) = ([], 0, 0)
	while 1:
		j = s.find(r, j)
		if j == -1:
			if i < len(s):
				out.append(s[i:])
			break
		if i < j + iM:
			out.append(s[i:j + iM])
		(i, j) = (j + iM, j + len(r))
	return out


def split_without_loss(s, split_p):
	result = []
	pipe_index = split_p.find('|')
	split_p = split_p.replace('|', '')
	split_index = s.find(split_p)
	begin = 0
	while split_index != -1:
		if split_index + pipe_index != 0:
			result.append(s[begin:split_index + pipe_index])
		begin = split_index + pipe_index
		split_index = s.find(split_p, split_index + len(split_p))
	if begin != len(s):
		result.append(s[begin:])
	return result


def split_without_loss(s, c):
	return [x for x in s.replace(c.replace('|', ''), c).split('|') if x]


import re

def split_without_loss(s, split_p):
	return [i for i in re.sub(''.join([i for i in split_p if i != '|']), split_p, s).split('|') if i]


def split_without_loss(s, sp):
	(i, sp) = (sp.index('|'), sp.replace('|', ''))
	r = s.split(sp)
	for k in range(len(r) - 1):
		r[k] += sp[:i]
		r[k + 1] = sp[i:] + r[k + 1]
	return [i for i in r if i]


def split_without_loss(s, split_p):
	sep = split_p.replace('|', '')
	s1 = s.replace(sep, split_p)
	s1 = s1.strip('|')
	return s1.split('|')


def split_without_loss(s, a):
	aa = a.split('|')
	ss = s.replace(aa[0] + aa[1], a).split('|')
	return [i for i in ss if i]


def split_without_loss(s, split_p):
	to_find = split_p.replace('|', '')
	with_bar = s.replace(to_find, split_p)
	return [x for x in with_bar.split('|') if x != '']


def split_without_loss(s, split_p):
	return s.replace(split_p.replace('|', ''), split_p).lstrip('|').rstrip('|').split('|')