DEV Community

Arun Kumar G
Arun Kumar G

Posted on

2 1

JavaScript Challenges - Strings

Q1. Write a function to validate given email has @ or not

    isValidEmail("test@gmail.com") === true
    isValidEmail("testmail.com") === false
Enter fullscreen mode Exit fullscreen mode

Q2. Write a function check weather given email id is gmail or not

    isGmailId("test@gmail.com") === true
    isGmailId("test@yahoo.com") === false
Enter fullscreen mode Exit fullscreen mode

Q3. Write a function to accept firstName and lastName as param and should return fullName

   getFullName("John","Snow") == "John Snow";
Enter fullscreen mode Exit fullscreen mode

Q4. Uppercase the first character

   upperFirst("john") == "John";
Enter fullscreen mode Exit fullscreen mode

Q5. Truncate a given string with a limit

   truncate("What I'd like to tell on this topic is:", 20) = 
   "What I'd like to te…"
   truncate("Hi everyone!", 20) = "Hi everyone!"
Enter fullscreen mode Exit fullscreen mode

Q6. Function to extract currency value from given string

extractCurrencyValue('$120') === 120
Enter fullscreen mode Exit fullscreen mode

Q7. Function mask every A with

    stringMask("Its A sunny weather") === "Its # sunny we#ther";
Enter fullscreen mode Exit fullscreen mode

Q8. Function to Count Decimal Points in a given number?

   getDecimalCount("43.20")  2
   getDecimalCount("400")  0
   getDecimalCount("3.1")  1
Enter fullscreen mode Exit fullscreen mode

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay