Javascript Everywhere

Help for javascript developer

Javascript Everywhere in the world

Sunday, May 03, 2020

Javascript Challenges: Sum of two value without using +(plus) sign

sum of two value without using + sign
Write a program for the above logic

Introduction:
Developer requests us to find a solution for this challenge. Challenge is the sum of two values without using plus sign using javascript. Developer are really in to solve challenges and give multiple solutions.

Challenge:

   Write a logic for below input:
Input Output
getSumOfVal(10, 20) 30
getSumOfVal(10, -10) 0
getSumOfVal(5, 8) 13
getSumOfVal(0, 0) 0

Program Description: Write a program sum of two value without a plus sign.

The program output is: 1)

function getSumOfVal(a, b) {
    if (b == 0) {
        return a;
    } else {
        return getSumOfVal(a ^ b, (a & b) << 1)
    }
};
Explanation:
-> This is a program performs using a bitwise operator.
->

function getSumOfVal(a, b) {
    if (b == 0) {
        return a;
    } else {
        return getSumOfVal(10 ^ -10, (10 & -10) << 1)
        // 10 ^ -10 = -4 
        // (10 & -10) << 1 = 4
        // -4 + 4 = 0
    }
};
-> It's simple if you want to understand more logic then contact me I will explain in details.

2)
const getSumOfVal = (a,b) => b ? getSumOfVal(a ^ b, (a & b) << 1) : a;
Explanation:
-> Same as above just use ES6 syntax here.
-> You can write a whole program in a single line as well.

3)
const getSumOfVal = (a, b) => eval(''.concat(a).concat(String.fromCharCode(0x2B)).concat(b));
-> Here use plus sign in character code. so don't be confuse about string and fromCharCode

4)
function getSumOfVal(x, y) {
    return Math.log2(2**x * 2**y);
}
Explanation:
-> Here we can use the log2 method for sum. Math is a default javascript library.

5)
function getSumOfVal(a, b) {
    return a - - b;
}
Explanation:
-> Very basic and simple method for sum.
-> Many developers give solutions using this method and we congratulate those use this method.
-> This method is very easy to use.
-> Rule is  ++ = +, -+ = -, --=+, +-=-
-> In-word: plus, plus = plus, minus, plus = minus, plus, minus = minus, minus, minus = plus
6) Example: 10 - - 10 = 20, 10 - 10 = 0

For this blog, my purpose is just clear developer logic and improve your skill and fundamentals of operator provided by javascript and another language. In my Fb(javascript everywhere) page many developers failed to solve this because he only thinks complex.

If you like to give challenges to the developer then contact me I will create a blog and post with your name and share it.

Other: Math series solve using javascript.
Maths series solve using javascript

Friday, May 01, 2020

Javascript Challenges: Maths series program using javascript



Write a program on maths series
Write a program on maths series
Introduction:
    Many developers are failed to make proper function or algorithm. We give challenges and many of them are sorted out. Today challenge is just a series of mathematics. Write a program on this series dynamic. the solution is easy as you think.
In mathematics, a series is, roughly speaking, a description of the operation of adding infinitely many quantities, one after the other, to a given starting quantity. 
 Mathematics give proper solution of this series and developer are able to convert in to execute.
The study of series is a major part of calculus and its generalization, mathematical analysis
Series are used in most areas of mathematics, even for studying finite structures (such as in combinatorics), through generating functions. In addition to their ubiquity in mathematics, infinite series are also widely used in other quantitative disciplines such as physicscomputer sciencestatistics, and finance.

Challenge:

   Write a logic for below input:
Input Output
inNumber(5) 5, 9, 13, 17, 21
inNumber(2) 5, 9
inNumber(9) 5, 9, 13, 17, 21, 25, 29, 33, 37
inNumber(1) 5

Program Description: Write a program with for maths serial solution for the above output

The program output is: 1)

function inNumber(data) {
   let number = 1;
   let arr = []; 
   for (var i = 1; i <= data; i++){
     number = number + 4;
     arr.push(number);
   }
   console.log(arr);
}


const numberIncrease = (maxLength) => {
  let array = [];
  let currentNumber = 5;
  for (let index = 0; index < maxLength; index += 1) {
    index === 0 ? array.push(currentNumber) : array.push((currentNumber += 4));
  }
  return array.join(", ");
 }

Explanation:
1) create one function that can return value in the string, array, or any format.
2) declare the blank array variable for storing the output of the result.
3) Now the main logic is started
4) create a for loop or while loop
5) while loop and for loop both are used fully for this program you may use recursion as well
6) but the point goes with simple and understandable.
7) Now increment number with 4 and default is one so it's become 5 and push inside an array
8) This loop continues until length of numbers like 5, 6, 7, 8 or any other
9) In last you can print this number or return as well
10) Now your program is done so far if you have any comment related to this program then feel free to contact me with this blog link I will explain in more batter way

For this blog, my purpose is just clear your logic and improve your skill and fundamentals of mathematics. In my Fb(javascript everywhere) page many developer failed to solve this because he only thinks complex.

If you like to give challenges to the developer then contact me I will create a blog and post with your name and share it.

Other: Swap to a variable without using the third one. more than 3 solutions provided.
Swap to a variable without the help of the third variable

Tuesday, April 28, 2020

JavaScript Challenges: Count a string and add more character if a string is less than 25 character

Count a string and add remain character
Make string fix size and fill with another character

Introduction:

    Many javascript developers are missing functions provided by javascript. This is a simple program just append and prepend string if the given string length is less then 25. Many developers try with loop and long logic for this. Our question is why we not using built-in functions. Let me try with built-in functions.

Challenge:

   Write a logic for below input:
Input Output
Javascript Everywhere Javascript Everywhere----
~~~~Javascript Everywhere
You are a good developer You are a good developer-
~You are a good developer
New New----------------------
~~~~~~~~~~~~~~~~~~~~~~New
Challenges Challenges---------------
~~~~~~~~~~~~~~~Challenges

Program Description: Write a program if the string length is 25 characters then add ~(tilde) sign at prefix and add -(dash) sign at postfix.

The program output is:
1)

function stringModify(str) {
    console.log(str.padEnd(25, '-'));
    console.log(str.padStart(25, '~'));
}

Another program:
2)

function stringModify(str){
   const sign1="-";
   const sign2="~";
   let output=str.length>25 ? str: str.concat(sign1.repeat(25 - str.length), '\n', sign2.repeat(25 - str.length), str);
   return output;
}
console.log(stringModify("New"));

Explanation:
1) In the first program, we use the built-in function provided by javascript.
2) The function is padEnd and padStart

padEnd()

This is a string function. The padEnd() method adds a current string in the given string. So the result is reached to the given length. String added at end of the current string. Ex:

const str1 = 'Welcome to javascript';

console.log(str1.padEnd(25, '_'));
// expected output: "Welcome to javascript____"

const str2 = '1000';

console.log(str2.padEnd(5));
// expected output: "1000 "

The default replaces string is space.

padStart()

This is also a string function. The padStart() method also expand string. So the result is reached to the given length. String added at the starting of the current string. Ex:

const strTemp = 'Welcome to javascript';

console.log(strTemp.padStart(25, '_'));
// expected output: "____Welcome to javascript"

const numberVal = '500';

console.log(numberVal.padEnd(5));
// expected output: "  500"

The default replaces character is space.
Many ways you can do this but most useful and preferable is using the build-in function.
Other: Swap to a variable without using the third one. more than 3 solutions provided.
Swap to a variable without the help of the third variable

Monday, April 27, 2020

JavaScript Challenges: How to swap two variable without using third one?

Without third variable swap to variable
Swap to variable in javascript without using the third variable

Introduction:
    Many javascript developers ask a question, How many ways to swap two variables without using third. Our answer is there are many ways we can achieve this but we always go with the easiest and fast solution. Every language provides a different way of doing the swap variables.

Challenge:

Challenge is declared two variable and swap value between without using the third variable like

Input: var a = 10;
           var b = 20;
          console.log(a, b) is give output like (10, 20)
Output: console.log(a, b) is output like (20, 10)

The logic of this program is many, we provide the best solution here:
The program output is:
1)

var a = 10;
var b = 20;
[a, b] = [b, a];
console.log(a, b);
2)
let a = 10;
let b = 20;
a = a * b;
b = a / b;
a = a / b;
console.log(a, b)
3)

var a = 10;
var b = 20;
console.log(a,b);
a = new Array(a,b);
b = a[0];
a = a[1];
console.log(a,b);

Explanation: There are many ways you can perform this program. You are free to ask question and comment, I will reply and give you a proper solution.


Other: Reverse string without using the built-in function

Sunday, April 26, 2020

JavaScript Challenges: Reverse string without any built in function

How to reverse a string without using function
Reverse string without using the built-in function

Introduction:
    Every javascript function has some logic for modification like toLowerCase(), toUpperCase(), join() and etc.. Today we are going to perform one program is revere string without any built-in function. Many developers doing this.

Challenge:

   Write a logic for below input:
Input Output
Javascript Everywhere erehwyrevE tpirsavaJ
Hello Developer repoleveD olleH
Was it a car or a cat I saw? ?was i tac ro rac a ti saW

Program Description: Write an algorithm to reverse a string without using any function provided by javascript. like reverse(), join(). Only allow length() is you really need.

The program output is:
1)

function reverseString(str) {
    var reversedString = '';
    for(let i= str.length - 1; i >= 0; i--)
    {
        reversedString += str[i];
    }
    return reversedString;
}

Another program with reverse and other function:
2)

"Javascript Developer improve skill here".split('').reverse().join('');
3)

"Jsgrip is website for developer".split('').reduce((temp1, temp2) => temp2 + temp1);

Explanation: Using array creates one variable blank and then inside for loop starting from the length of string and end to 0. From the last index assign value to the variable and after a loop just return that variable.

There are another way as well you can do achieve this output.
Other: Challenges here is Count lowercase, uppercase and number from string
https://jsgrip.blogspot.com/2020/04/javascript-challenges-count-lowercase.html

Saturday, April 25, 2020

JavaScript Challenges: Count lowercase, uppercase and number from string.

From Javascript everywhere page in facebook
Count a lowercase, uppercase, and number from string

Introduction:
    Welcome to the new javascript challenge. This problem is count Number, Lowercase(small latter), Uppercase(capital latter) from the given string.

Challenge:

   Write a logic for below input:
Input Output
Javascript Everywhere [17, 3, 0]
100k+ developer JOIN community [14, 4, 3]
what is the sum of 3445 + 5443 [14, 0, 8]
THE WORLD [0, 8, 0]

Program Description: Write a function for display count of lowercase, uppercase, and number in [<Lowercase count>, <Uppercase count>, <Number count>]

The program output is:
1)

function getCount(str) {

    var lower = str.match(/[a-z]/g);

    var upper = str.match(/[A-Z]/g);

    var number = str.match(/[0-9]/g);

    return [
        lower ? lower.length : 0,
        upper ? upper.length : 0,
        number ? number.length : 0,
     ]
}
2)

function getCount(str) {
    return [(str.match(/[a-z]/g)||[]).length,(str.match(/[A-Z]/g)||[]).length,(str.match(/[0-9]/g)||[]).length]
}

Explanation:
1) First and second both programs almost the same.
2) In the second program, we just use inline syntax and in first we explain with clear output
3) We use a pattern for solving this problem.
4) The pattern is more power full in any language we perform multiple logic using a pattern.
5) A pattern is a reusable solution that can be applied in occurring software design in our case we use in javascript problem-solving.
6) Another way pattern is a template for how we solve problems.
7) Here we use just simple patterns like [A-Z], [a-z], [0-9] inside these braces we consider as count of the length.
8) If we need just a-z count uppercase or lowercase we use a pattern like [a-zA-Z] or [\s].
9) If any confusion or query regarding pattern contacts me I will help you.

The developer just needs to write a pattern and find character and count.
There are many other solutions for this program but this is easier and fast.
This is the blog you find more challenges and other javascript information.

Other: Challenges here is count number of the vowel from string
https://jsgrip.blogspot.com/2020/04/javascript-challenge-count-vowel-number.html

Friday, April 24, 2020

JavaScript Challenge: Count a Vowel number from string

Find vowel number from string
count a vowel from string

Introduction:
    I am a Javascript developer. Now day javascript has become the most popular worldwide. But many javascript developers do his routine task daily and never try to learn more and improve his skill. So I am thinking to improve his skills and always give challenges and knowledge.

Challenge:

   Write a logic for below input:
Input Output
Javascript Everywhere 7
You are a good developer 11
Challenges 3
Welcome to the blog 6

The program output is:
1)

function getCount(str) {
    return (str.toLowerCase().match(/[aieou]/gi) || []).length;
}
2)

function getCount(str) {
    return str.length - (str.toLowerCase().replace(/[aeiou]/g, '') || []).length;
}
This is simple logic using "aeiou" pattern and you can directly identify vowel from the string.
Many developers try to use loop and indexOf that's also work but it long and more complex than the above program.

This is the blog you find more challenges and other javascript information.