-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreak camel case.js
93 lines (66 loc) · 2.08 KB
/
break camel case.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//https://www.codewars.com/kata/5208f99aee097e6552000148/train/javascript
// complete the function
// complete the function
function solution(string) {
string = string.split('').map(function (el) {
if (el === el.toUpperCase()) {
el = ' ' + el
}
return el
})
return string.join('')
}
// function solution(string) {
// console.log("phrase is"+string);
// const re = /[A-Z]/g;
// let found = string.match(re);
// if(found === null){
// return string;
// }
// console.log(found);
// let newArr = [...string];
// console.log(`newArr is ${newArr}`);
// let repeated;
// const foundSorted = found.sort();
// for(let i = 0; i<foundSorted.length;i++){
// if(foundSorted[i] === foundSorted[i+1]){
// repeated = true;
// console.log("REPEATED");
// }
// }
// for(let i = 0; i<found.length; i++){
// // let indx = string.indexOf(found[i]);
// let lastIndx;
// let indx;
// indx = newArr.indexOf(found[i]);
// //TODO change loop to be in the phrase not the found letters?
// newArr.splice(indx, 0, " ");
// lastIndx = indx;
// console.log(`index we changing is ${indx}
// iteration is ${i} and lastIndex is ${lastIndx}`);
// }
// let returnArr = newArr.join("");
// if(repeated){
// let lastIndx;
// for (let i = 0; i<newArr.length; i++){
// if (newArr[i] === " " && newArr[i] === newArr[i+1]){
// lastIndx = i+1;
// }
// }
// // let lastIndx = returnArr.lastIndexOf(" ");
// newArr = [...returnArr];
// let checkLetter = newArr[lastIndx+1];
// console.log("check letter is: "+ checkLetter);
// for(let i = lastIndx+2; i<newArr.length; i++){
// if (newArr[i]===checkLetter){
// newArr.splice(lastIndx, 1);
// newArr.splice(i-1, 0, " ");
// }
// }
// }
// returnArr = newArr.join("");
// console.log(newArr);
// console.log(returnArr);
// return returnArr;
// // console.log(string.indexOf(found[0]));
// }