let message = "How are you? Eh, ok. Low or Lower? Ohhh." function findWord(text) { let arrayLetters = text.split(''); let result = []; arr.forEach(function(value, index, array) { if ( value == value.toUpperCase() && value != ' ' && value != '?' && value != '.' && value != ',' ) { result.push(value); } }, 0); result = result.join(''); console.log(message); console.log("Секретный текст: " + result); } 

Is it possible to rewrite this condition in a shorter way?

 if ( value == value.toUpperCase() && value != ' ' && value != '?' && value != '.' && value != ',' ) { 
  • one
    depending on what you want to end up with. After all, you did not write this - Alexey Shimansky
  • I am interested in a shorter implementation of this condition if (value == value.toUpperCase () && value! = '' && value! = '?' && value! = '.' && value! = ',') - Denisoed
  • You can use the regular season - Sublihim
  • one
    value >= 'A' && value <= 'Z' - Grundy
  • one
    @Grundy, yeah, or so, you just need to warn the author that when small letters appear, Russian letters including Y, the logical condition will swell up noticeably - Duck Learns to Hide

1 answer 1

It is not very clear what you need, but if the task is to choose capital Latin letters, then you can replace that condition with:

 if (/[AZ]/.test(value)) { 

Or even the whole function on:

 function findWord(text) { result = text.replace(/[^AZ]+/g, ''); console.log(message); console.log("Секретный текст: " + result); } 
  • 3
    How is this not very clear? You need более короткая реализация данного условия if ( value == value.toUpperCase() && value != ' ' && value != '?' && value != '.' && value != ',' ) : D - Alexey Shimansky