JJ
JJ
if (arr.length === 0) {
return undefined;
} else {
return maxVal;
}
}
// Example usage
const myArray = [5, 8, 2, 10, 3];
const maxValue = findMaxValue(myArray);
console.log("Maximum value:", maxValue);
return count;
}
// Example usage
var myArray = [1, 2, 3, 2, 4, 2, 5];
var targetElement = 2;
var occurrenceCount = countOccurrences(myArray, targetElement);
console.log("Occurrences of", targetElement + ":", occurrenceCount);
///////////////////////////////////
Occurrences of 2: 3
function generateFibonacciSequence(length) {
if (length <= 0) {
return [];
} else if (length === 1) {
return [0];
} else if (length === 2) {
return [0, 1];
} else {
var sequence = [0, 1];
sequence.push(nextNumber);
}
return sequence;
}
}