
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript Recursion finding the smallest number?
Let’s say the following is our array −
var numbers=[10,101,76,56,5,210,3,100];
To find the smallest number, the code is as follows −
Example
function findMinimumElementUsingRecursive(numbers) { if (numbers.length==1){ return numbers[0]; } else if(numbers[0]>numbers[1]) { return findMinimumElementUsingRecursive(numbers.slice(1)); } else { return findMinimumElementUsingRecursive([numbers[0]].concat(numbers.slice(2))); } } var numbers=[10,101,76,56,5,210,3,100]; console.log("The minimum element is="+findMinimumElementUsingRecursive(numbers));
To run the above program, you need to use the following command −
node fileName.js.
Output
Here, my file name is demo152.js. This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo152.js The minimum element is=3
- Related Questions & Answers
- Finding smallest number using recursion in JavaScript
- Finding the smallest fitting number in JavaScript
- Finding the smallest multiple in JavaScript
- Finding smallest number that satisfies some conditions in JavaScript
- Finding the smallest good base in JavaScript
- Finding greatest digit by recursion - JavaScript
- Finding difference of greatest and the smallest digit in a number - JavaScript
- Finding the largest and smallest number in an unsorted array of integers in JavaScript
- Finding a number of pairs from arrays with smallest sums in JavaScript
- Finding the smallest value in a JSON object in JavaScript
- Finding the greatest and smallest number in a space separated string of numbers using JavaScript
- Finding second smallest word in a string - JavaScript
- Finding smallest sum after making transformations in JavaScript
- Finding out the Harshad number JavaScript
- Finding product of an array using recursion in JavaScript
Advertisements