π 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.
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)