-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhackerrank13.js
35 lines (28 loc) · 875 Bytes
/
hackerrank13.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
// Parse camelCase words
// Parsear palabras en camelCase
function parseCamelCase(word) {
word = word.split('');
var wordBeginIndex = 0;
var parsedWords = [];
for (var i = 0, length = word.length; i < length; i++) {
var isLastIndex = i === length - 1;
if (word[i] === word[i].toUpperCase() || isLastIndex) {
parsedWords.push(word.slice(wordBeginIndex, !isLastIndex ? i : i+1).join(''));
wordBeginIndex = i;
}
}
return parsedWords;
}
// test cases
console.log(assert(parseCamelCase('saveThisText'), ['save','This', 'Text']));
console.log(assert(parseCamelCase('sTText'), ['s','T', 'Text']));
console.log(assert(parseCamelCase('saas'), ['saas']));
// assert function
function assert(a, b) {
if (typeof a === 'object') {
a = JSON.stringify(a);
b = JSON.stringify(b);
}
console.log(a + ' === '+ b)
return a === b;
}