function countWhitespaceCharacters(str) {
let count = 0;
const length = str.length;
for (let i = 0; i < length; i++) {
if (/\s/.test(str[i])) {
count++;
}
}
return count;
}
const str = "Node.js \n Programming \r Language \t ";
console.log("Total white spaces: " + countWhitespaceCharacters(str));
/*
run:
Total white spaces: 10
*/