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