Showing posts with label PROBLEMS. Show all posts
Showing posts with label PROBLEMS. Show all posts

Sunday, October 30, 2022

JavaScript Functions as JavaScript Variables

In Javascript instead of declaring and executing a function in two different steps.
for example
step 1 - 
function add(a,b){return a+b;}
step 2-
add(3,4);
result 7

Javascript provides an approach to declare and execute the function immediately. Which is known as IIFE(Immediately Invoked Function Expression)

Example:
(
function add(x,y){
alert(x+y);
})();

Saturday, October 29, 2022

Birthday Cake Candles Problem(Hacker Rank)

 You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.

Example

The maximum height candles are  units high. There are  of them, so return .


SOLUTION:

    public static int birthdayCakeCandles(List<int> candles)
    {
       int max = candles.Max();
       int result = candles.Count(x=>x==max);
       return result;
    }

Description
  1. Find the tallest candle.
  2. Count the number of tallest candles using linq.
  3. return result.


JavaScript Functions as JavaScript Variables

In Javascript instead of declaring and executing a function in two different steps. for example step 1 -  function add(a,b){return a+b;} ste...