19 Feb 2023

A Javascript Program to find the count of unique string {a: 13, b: 12, c:13}

A Javascript Program to find the count of unique string -

Example:

var str = 'aaabbcccabcbcacbaabcbcabbccaaaabcbc';


Program: 

Part A:  Program to find the unique character in the given String -

var uniqLetter = [];

str.split('').map((item) =>{

    if(!uniqLetter.includes(item)){

        uniqLetter.push(item);

    }

});

Part B:  Now iterate on unique String & find the total count of the characetr in the given String & form the object -

var temp = {};

uniqLetter.map((i) => {

         temp = {...temp,

           ...{[i]: str.split(i).length}

           };

});

console.log(temp);

5 Feb 2023

Java SpringBoot Configuration Examples -

 Java SpringBoot Configuration Example -

File - application.properties

server.port=1010

+------------------------------------------------------------------------+

logging.level.org.springframework.web: DEBUG

logging.level.org.hibernate: ERROR

+------------------------------------------------------------------------+

spring.application.name=login-service

spring.datasource.url=jdbc:mysql://localhost:3306/microservices

spring.datasource.username=root

spring.datasource.password=root@12345

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.jpa.database-platform = org.hibernate.dialect.MySQLDialect

spring.jpa.generate-ddl=true

spring.jpa.hibernate.ddl-auto = update

spring.jpa.properties.hibernate.globally_quoted_identifiers=true

+------------------------------------------------------------------------+

spring.security.user.name=admin

spring.security.user.password=admin

spring.security.user.roles=manager

Difference between Javascript Map & Filter Method -

Difference between Javascript Map & Filter Method  -

Program I: 

var arr = [4, 24, 65, 13, 98];

var newArray = arr.map((i) => i + 20);

console.log(newArray);

Output:

(5) [24, 44, 85, 33, 118]


Program II: 

var arr = [4, 24, 65, 13, 98];

var newFilter = arr.filter((i) => i + 20);

console.log(newFilter );

Output:

(5) [4, 24, 65, 13, 98]


Finally, Ouput indicates that the main difference in using the map & filter is that filter doesn't change the value of array element while map can have the updated values for the elements. 

Map & Filter both method return the new array.

Map methos keeps all the indexes in the new Array while Filter keep only the true case index in new array.

 

29 Jan 2023

Thunk vs Saga (React Redux middlewares)

Useful Links

https://blog.devgenius.io/react-redux-middlewares-thunk-vs-saga-e346a25319b3