a
Size: a a a
a
a
VM
a
VM
a
a
В
CS
a
<a href=" ... ">кликни сюда</a>
C
NB
VL
var newStr = 'Hello my friend friend friend hello hello my';
var search = ['friend', 'hello', 'Hello', 'my', 'wtf'];
var results = [];
for (var i = 0; i < search.length; i++) {
results.push(0);
}
for (var str of newStr.split(' ')) {
var found = search.indexOf(str);
if (found !== -1) {
results[found]++;
}
}
console.log(results); // [ 3, 2, 1, 2, 0 ]
var newStr = 'Hello my friend friend friend hello hello my';
var search = ['friend', 'hello', 'Hello', 'my', 'wtf'];
var obj = newStr.split(' ').reduce((acc, v) => {
acc[v] = acc[v] ? (acc[v] + 1) : 1;
return acc;
}, {});
console.dir(obj); // Object { Hello: 1, my: 2, friend: 3, hello: 2 }
Object.entries(obj).forEach(([str,times])=>console.log(`Строка "${str}" встретилась ${times} раз.`));
// Строка "Hello" встретилась 1 раз.
// Строка "my" встретилась 2 раз.
// Строка "friend" встретилась 3 раз.
// Строка "hello" встретилась 2 раз.
var newStr = 'Hello my friend friend friend hello hello my';
newStr = newStr.split(' ');
var regexp05 = [/my/, /friend/, /Hello/, /hello/];
for(var i=0; i<newStr.length; i++){
for(var j=0; j<regexp05.length; j++){
var finish = regexp05[j].exec(newStr[i]);
if(finish){
console.log(finish[0] + ' ' + '['+j+']');
}
}
}
VL
PA
VL
PA
DA
AP