Update index.js

This commit is contained in:
afiqzudinhadi 2024-08-08 14:04:58 +08:00
parent 8d1008f650
commit 26f9ea170a

View file

@ -1,5 +1,10 @@
function countSmileys(arr) {
const smileyPattern = /^[:;][-~]?[)D]$/;
if (arr.length === 0) {
return 0;
}
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: 3
console.log(countSmileys([";]", ":[", ";*", ":$", ";-D"])); // Output: 1
console.log(countSmileys([])); // Output: 0