I'm checking whether character is capital letter or not by using javascript RegExp
function splitWords(text) {
const capReg = /[A-Z]/g;
const alphaNumReg = /[a-z0-9]/g;
for (let i = 0; i <= text.length - 1; i++) {
console.log(
text[i], text[i + 1], text[i + 2],
capReg.test(text[i]), capReg.test(text[i + 1]),
alphaNumReg.test(text[i + 2])
);
}
}
splitWords('ABCOption');
at case expected C, O, p, true, true, true Actual C, O, p, true, false, true
Please help me where i'm doing wrong