scrimba
Note at 1:35
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Note at 1:35
AboutCommentsNotes
Note at 1:35
Expand for more info
main.js
run
preview
console
function insertDashes(str) {
result = []
for (let i = 0; i < str.length - 1; i++) {
if (isAlpha(str[i]) && isAlpha(str[i+1])) {
result.push(str[i] + '-')
} else {
result.push(str[i])
}
}
result.push(str[str.length - 1])
return result.join('')
}

function isAlpha(char) {
return /^[a-zA-Z]$/.test(char)
}


/**
* Test Suite
*/
describe('insertDashes()', () => {
it('insert dashes in between chars', () => {
// arrange
const value = "aba caba";

// act
const result = insertDashes(value);

// log
console.log("result: ", result);

// assert
expect(result).toBe("a-b-a c-a-b-a");
});
});
Console
"result: "
,
"a-b-a c-a-b-a"
,
/index.html
LIVE