DEV Community

Cover image for Day 6/366
vishal.codes
vishal.codes

Posted on

Day 6/366

πŸš€ Today's Learning:

🌟 DSA

  • To Lower Case - Leetcode 709
  • Count vowels & consonants in a string

🌟 Dev

  • Abstraction and Private Variables/Methods in JS
  • Pass by Value vs Pass by Reference
  • Callback Hell and Prevention

πŸ” Some Key Highlights:

DSA

To Lower Case - Leetcode 709

Approach β†’ Iterate through the string β†’ if s[i] is β‰₯ 65 and s[i] ≀ 90 this means it’s a uppercase letter, so just add 32 to it so it goes to lowercase letter range. Note: uppercase and lowercase letters have a fixed difference of 32.

Image description

Count vowels & consonants in a string

Approach β†’ create two variables - vCount and cCount initialized with zero. Iterate through the given string β†’ if (s[i] == β€˜a’ || s[i] == β€˜A’ || s[i] == β€˜e’ ..and so on) increment vCount β†’ else if (s[i] β‰₯65 && s[i] ≀90 || s[i] β‰₯ 97 && s[i] ≀ 122) increment cCount. Now we get the count of both vowels and consonants in the string.

DEV

Abstraction in JavaScript involves hiding the complexity of code and showing only the necessary details. Private variables and methods are crucial for encapsulating data and preventing direct access from outside the scope. JavaScript doesn't have built-in support for private variables, but we can achieve this using closures.

In JavaScript, primitive data types like strings and numbers are passed by value, while objects (including arrays and functions) are passed by reference.

Callback hell refers to deeply nested callback functions, making code hard to read and maintain. Promises and async/await are modern solutions to mitigate callback hell.

Top comments (0)