It's interesting that isFinite doesn't work here
(It says :8,18: Argument of type 'string' is not assignable to parameter of type 'number'.):
But if we change 'the style of function'
from this
'function threeWords(text: string): boolean {'
to this
'function threeWords(text){'
it will work:
function threeWords(text: string): boolean { //function threeWords(text){
let arr = text.split(' ');
let sum = 0;
console.log(arr[0].match(/[0-9]/) == null)
for (let i = 0; i < arr.length; i++) {
if (isFinite(arr[i]) == false) {
sum++;
if (sum == 3) return true;
} else {
sum = 0;
}
}
return false;
}
//console.log(threeWords("Hello World hello"), true);
console.log(threeWords("He is 123 man"), false);
Created at: 2020/04/26 13:25; Updated at: 2020/04/28 05:54
The question is resolved.