-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathunbreakable.js
More file actions
36 lines (35 loc) · 831 Bytes
/
unbreakable.js
File metadata and controls
36 lines (35 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function join(arr, sep) {
if (sep === null) {
sep = ",";
}
var result = arr[0].toString();
for (var i = 1; i < arr.length; i++) {
result += sep + arr[i];
}
return result;
}
function split(str, sep) {
// Split a given string using a multi-character separator
// and return an array of the results.
if (sep === null) {
sep = ",";
}
var result = [];
if (sep === "") {
for (var i = 0; i < str.length; i++) {
result.push(str[i]);
}
return result;
}
var end = str.indexOf(sep);
while (end > -1) {
end = str.indexOf(sep);
if (end === -1) {
break;
}
result.push(str.slice(0, end));
str = str.slice(end + sep.length);
}
result.push(str);
return result;
}