-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayManipulation.js
More file actions
43 lines (31 loc) · 829 Bytes
/
arrayManipulation.js
File metadata and controls
43 lines (31 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//Task 1
function processArray (numbers){
return numbers.map(num => {
if (num%2 ===0){
return num*num;
} else{
return num*3;
}
});
}
//Example usage
const numbers = [1,2,3,4,5]
const processedNumbers = processArray(numbers);
console.log(processedNumbers);
//Task 2
function formatArrayStrings(strings,processedNumbers){
return strings.map((string,index)=>{
if (processedNumbers[index]%2 === 0){
return string.toUpperCase();
} else{
return string.toLowerCase();
}
});
}
//example usage
const strings =["My","Mom","is","the","best"];
const formattedArrayStrings = formatArrayStrings(strings,processedNumbers);
console.log(formattedArrayStrings);
module.exports = {
processArray,formatArrayStrings
};