seyi-adeleke/ToGgLe-CaSe

View on GitHub
src/index.js

Summary

Maintainability
A
0 mins
Test Coverage
module.exports = function toggle(text) {
    if (typeof text !== 'string') {
        return '';
    }
    return text.replace(/_|-|\./g, '').split('').map((letter, index) => {
        if (index % 2 === 0) {
            return letter.toUpperCase();
        }
        return letter.toLowerCase();
    }).join('')
        .trim();
};