Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
Print words with at least 4 consonants javascripts

Given the array ["cat", "dog", "reindeer", "penguin", "crocodile"], print all words with at least 4 consonants.

I don't know how to do it.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The commented code below can help you:

const animals = ["cat", "dog", "reindeer", "penguin", "crocodile"]
const vowels = ['a', 'e', 'i', 'o', 'u']

animals.forEach(animal=>{
  let counter=0
  //spliting the word in letters
  animal.split('').forEach(letter=>{
    //checking if the letter is really a letter and if it is not a vowel
    if(letter.toLocaleLowerCase()>='a'&&letter.toLocaleLowerCase()<='z'&&!vowels.some(v=>v===letter.toLocaleLowerCase()))
    counter++
  })
  if(counter>=4)
  console.log(animal)
})
about 4 years ago · Juan Pablo Isaza Report

0

With String match() method for pattern-matching, and Array.prototype.filter() for conditional screening of items, we can write a concise one-liner:

> const animals = ["cat", "dog", "reindeer", "penguin", "crocodile"]

> animals.filter( animal => animal.match(/[^aeiou]/gi).length >= 4)
["reindeer", "penguin", "crocodile"]

Do study regex as much as possible. Here are few resources: quick overview, deatiled demo

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!