There is an array of strings, it is necessary to check whether a certain substring is contained in each element of the array of strings, in case if at least one string does not exist, you need to return false.

The algorithm is terribly simple, but the task requires a minimum of characters in the code from the solution.

Are there any compact constructions for solving this problem in javascript? Language began to touch recently.

This thing is needed for checking in the if-else block.

  • In short, the code through regular expressions. - Alexey Drizhakov 7:42 pm
  • Add an example of an array, so that it would be easier to write a solution, rather than composing your own array, which will take much more time - Pavel Igorevich

2 answers 2

const test = ['тест', 'тестировщик','те2ст']; const test2 = ['тест', 'тестировщик','тестовый']; let result = test.every(elem => ~elem.indexOf('тест')); let result2 = test2.every(elem => ~elem.indexOf('тест')); console.log(result); console.log(result2); 

    Take for example this array:

     var test = ['Привет0', 'Привет1', 'Привет2', 'При_вет3']; 

    If you need to check whether the substring 'Hello' is contained in each element of the array, use this function:

     function include(array, key) { var regexp = new RegExp(key, 'g'); return array.join(' ').match(regexp).length == array.length; } console.log(include(test, 'Привет')); // false