-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs140108.js
More file actions
25 lines (21 loc) · 789 Bytes
/
Copy pathjs140108.js
File metadata and controls
25 lines (21 loc) · 789 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
const solution = (s) => {
let pointWord = ""; // 기준 단어
let pointCount = 0; // 기준 단어 카운트
let otherCount = 0; // 다른 단어 카운트
return [...s].reduce((result, word, index, arr) =>{
// 카운트 수가 같을 경우 기준 초기화
if(pointCount==otherCount){
pointWord = word;
otherCount = 0;
pointCount = 0;
}
// 단어 비교 후 숫자 카운트
pointWord==word&&++pointCount||++otherCount;
result.push(result.pop()+word);
arr.length-1!=index&&pointCount==otherCount&&result.push("");
return result;
},[""]).length
}
console.log(solution("banana"))
console.log(solution("abracadabra"))
console.log(solution("aaabbaccccabba"))