// Array to store words updated with dashes
let dashWords = [];
// Split given words by spaces
words = (arr.split(' '));
// Iterate through list of words
for (let word of words) {
// New string to store updated word with dashes
let dashWord = "";
// Iterate through letters and add dash
for (let i = 0; i < word.length; i ++) {
if (i < word.length - 1) {
dashWord += word[i] + "-";
}
// Don't add dash after last letter in word
else {
dashWord += word[i];
}
}
// Push dash word to array
dashWords.push(dashWord);
}
// Join two words into string and return
return dashWords.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");
});
});
function insertDashes(arr) {