Posts

Showing posts from April, 2021

String literal and its concatenation syntax in angular

How to define String literal and its concatenation in angular?  You can define a string literals  or get response data from back end API's then use the below concatenation syntax. The first thing, you need to remember, use back quote( `) , doller ( $) , open braces( { ) and close braces ( } ) symbols. Example:  let str1='xyz'; let str2 = 'abc';  let outputStr = `${str1}add${str2}`;  // xyzaddabc  

Replace substring in Angular

 Simple way to substitute new sub string in original String. let stringValue = 'JavaScript programing concepts ' let updatedStringValue = stringValue. replace ( 'JavaScript' , 'Angular' );   Output:   Angular programming concepts

Array Journey - Maximum sum rate

Image
 Description:  A pointer is at the first index of any array/Array list, and a sum start at the value of position. Move the pointer to the end of the array in the ranging from 1 to max step. At each step add the value of an array element at the pointer to the sum. Return the max sum that is achieved. The utility code snippet for the above problem. private static int calculateMaxSumRateWithMaxSteps ( List < Integer > arrList, int maxSteps){ Integer [] arr = arrList.toArray( new Integer[arrList.size()]); if ( arr . length == 0 ){ return arr [ 0 ]; } if ( arr . length == 1 ){ return arr [ 1 ]; } int firstSum = 0 ; int secondSum = 0 ; int outputSum = 0 ; int count = 0 ; for ( int i = 0 ; i < arr . length ; i++){ if (i == 0 ){ firstSum = arr [i]+ arr [i+ 1 ]; secondSum = arr [i]+ arr [i+ 1 +maxSteps- 1 ]; cou...