scrimba
Note at 0:46
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 0:46
AboutCommentsNotes
Note at 0:46
Expand for more info
main.js
run
preview
console
function insertDashes(arr) {
// 1. split string into array of substrings based on space delimiter
const substringsArr = arr.split(" ");

// 2. for each substring
for (let i= 0; i<substringsArr.length; i++){
// a. split into array of characters
// b. create new substring by joining with "-"
// c. update array with new substring result
substringsArr[i] = substringsArr[i].split("").join("-");
}
// 3. create and return result string by joining result substrings with " "
return substringsArr.join(" ");
}



/**
* 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
"String split by spaces: aba,caba"
,
[
"a-b-a"
,
"caba"
]
,
[
"a-b-a"
,
"c-a-b-a"
]
,
"result: "
,
"a-b-a c-a-b-a"
,
/index.html
LIVE