0% found this document useful (0 votes)
7 views

Lab 3

Uploaded by

mostaffanaada416
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Lab 3

Uploaded by

mostaffanaada416
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Tasks:

1. Write a JavaScript function which will take an array of numbers


stored and find the second lowest and second greatest numbers.

Ex: input : [1,2,3,4,5,1,5]


Expected Output : 2,4

2. Write a JavaScript function that accepts a string as a parameter


and converts the first letter of each word of the string in upper
case.

Ex: input: 'the quick brown fox'


Expected Output: 'The Quick Brown Fox '

3. Write a function that takes an object as an argument and prints


all key-value pairs. Test it by passing the student object.

Input Output
4. Create an object named library with a books property that is an
array of objects, where each book has title, author, and year
properties. Write a function that logs the title of each book in
the library.

5. Write a function applyOperation that takes two numbers and a


function as parameters. applyOperation should call the passed-
in function with the two numbers and return the result. Test it
by passing different operations like addition and multiplication.

6. Create a function named processArray that takes an array and a


callback function. The function should apply the callback to each
element in the array and log the results. Test it by passing an
array of numbers and a callback that squares each number

var numbers = [1, 2, 3, 4, 5];


Function Call : processArray(numbers, square);
Expected output: 1, 4, 9, 16, 25

You might also like