Javascript Everywhere

Help for javascript developer

Javascript Everywhere in the world

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