recursive function in js
function pow(x, n) {
if (n == 1) {
return x;
} else {
return x * pow(x, n - 1);
}
}
alert( pow(3, 3) ); // 27// Count Up
function countup(n) {
//Base case
if (n < 1) {
return [];
} else {
// The Recursion
const countArray = countup(n - 1);
countArray.push(n);
return countArray;
}
}
// Count Down
function countdown(n) {
// Base case
if (n < 1) {
return [];
} else {
// The Recursion
const count = countdown(n - 1);
count.unshift(n);
return count;
}
}
// User Defined
function rangeOfNumbers(startNum, endNum) {
// Base case
if (startNum - endNum === 0) {
return [startNum];
} else {
// The Recursion
const count = rangeOfNumbers(startNum, endNum - 1);
count.push(endNum);
return count;
}
}
Also in JavaScript:
- if both td data are same then merze how in javascript
- js how to convert vh to pixel
- reactjs compile subdomine
- This syntax requires an imported helper named '__spreadArrays' which does not exist in 'tslib'. Consider upgrading your version of 'tslib'.ts
- javascript add element to array
- javascript loop over the alphabet and return the vowels
- javascript vererbung Klasse extends super constructor
- check if a variable is undefined jquery
- random number js
- react-google-maps satelite
- close browser tab using jquery
- for loop stack overflow js
- javascript for loop return index
- p5js unset fill
- making js local function globally accessible
- 2. When will the validation functions be called in the react js
- VS javascript can't import file 3 folders up
- discord bot
- remove prefix js
- last index of array js
- remove duplicate objects from array javascript
- trigger a click on page load jquery
- form reset jquery
- initialize javascript array variable