JavaScript Coding Challenge #5

Alternating Characters

JavaScript solution

function nrOfDeletions(str) {
var count = 0;

return count;
}
function nrOfDeletions(str) {
var count = 0;
str.split(''); return count;
}
function nrOfDeletions(str) {
var count = 0;
str.split('').reduce(function(previous, current) { return current; }, ''); return count;
}
function nrOfDeletions(str) {
var count = 0;
str.split('').reduce(function(previous, current) { if(previous === current){
count++;
}
return current; }, ''); return count;
}

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store