Update index.js
This commit is contained in:
parent
8d1008f650
commit
26f9ea170a
1 changed files with 6 additions and 0 deletions
6
index.js
6
index.js
|
|
@ -1,5 +1,10 @@
|
||||||
function countSmileys(arr) {
|
function countSmileys(arr) {
|
||||||
const smileyPattern = /^[:;][-~]?[)D]$/;
|
const smileyPattern = /^[:;][-~]?[)D]$/;
|
||||||
|
|
||||||
|
if (arr.length === 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return arr.filter((face) => smileyPattern.test(face)).length;
|
return arr.filter((face) => smileyPattern.test(face)).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -7,3 +12,4 @@ function countSmileys(arr) {
|
||||||
console.log(countSmileys([":)", ";(", ";}", ":-D"])); // Output: 2
|
console.log(countSmileys([":)", ";(", ";}", ":-D"])); // Output: 2
|
||||||
console.log(countSmileys([";D", ":-(", ":-)", ";~)"])); // Output: 3
|
console.log(countSmileys([";D", ":-(", ":-)", ";~)"])); // Output: 3
|
||||||
console.log(countSmileys([";]", ":[", ";*", ":$", ";-D"])); // Output: 1
|
console.log(countSmileys([";]", ":[", ";*", ":$", ";-D"])); // Output: 1
|
||||||
|
console.log(countSmileys([])); // Output: 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue