xxxxxxxxxx
const numbers = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9, 10, 11],
];
let largestArray = numbers[0].length;
for (let i = 1; i < numbers.length; i++) {
if (numbers[i].length > largestArray) {
largestArray = numbers[i];
for (let j = 0; j < largestArray.length; j++) {
console.log(numbers[i][j]);
}
}
}
//it will print 7, 8, 9, 10, 11 as these numbers are in largest array;
xxxxxxxxxx
const array1 = [1, 3, 2];
Math.max(array1);
// expected output: 3
xxxxxxxxxx
const result = (data) => {
let max = 0;
for (let i = 0; i < data.length; i++) {
if (data[i] > max) {
max = data[i];
}
}
console.log("===> :: max", max);
}
const inputData = [2, 3, 5, 4, 54, 69, 4, 44, 3, 6, 45, 6, 4, 6]
result(inputData);
xxxxxxxxxx
const array = [3 , 6, 2, 56, 32, 5, 89, 32];
let largestNum= array[0];
for (let i=1; i<array.length; i++){
if (array[i]>largestNum) {
largestNum = array[i];
}
};
console.log(largestNum);
xxxxxxxxxx
function largestElements(numbers) {
var largest = 0;
for (let i = 0; i < numbers.length; i++) {
var elements = numbers[i];
if (elements > largest) {
largest = elements;
}
}
return largest;
}
const numbers = [2, 3, 4, 8, 5, 2, 4];
console.log(largestElements(numbers));
//Output: 8
xxxxxxxxxx
const getLargest = (arr) =>
arr.reduce((largest, num) => Math.max(largest, num));
const arr = [13, 7, 11, 3, 9, 15, 17];
console.log(getLargest(arr)); // 17
xxxxxxxxxx
function maisBaratosQue(valor, precos) {
return precos.filter(p => p <= valor);
}
xxxxxxxxxx
#include <stdio.h>
int main() {
int n;
double arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
printf("Enter number%d: ", i + 1);
scanf("%lf", &arr[i]);
}
// storing the largest number to arr[0]
for (int i = 1; i < n; ++i) {
if (arr[0] < arr[i]) {
arr[0] = arr[i];
}
}
printf("Largest element = %.2lf", arr[0]);
return 0;
}