-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayManipulation.js
More file actions
38 lines (27 loc) · 904 Bytes
/
arrayManipulation.js
File metadata and controls
38 lines (27 loc) · 904 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
const readlineSync = require('readline-sync');
function processArray() {
let y = readlineSync.prompt();
y = y.split(',').map(Number)
let processedArr = y.map(num => num % 2 === 0 ? num * num : num * 3);
return processedArr;
}
console.log('Enter an array of numbers separated by commas: ');
let processedArr = processArray();
console.log(processedArr);
function formatArrayStrings() {
let yStr = readlineSync.prompt();
yStr = yStr.split(',');
let formatArr = [];
for (let i = 0; i < yStr.length; i++) {
if (processedArr[i] % 2 === 0) {
formatArr.push(yStr[i].toUpperCase())
}
else {
formatArr.push(yStr[i].toLowerCase())
}
}
return formatArr;
}
console.log('Enter an array of strings separated by commas: ');
console.log(formatArrayStrings(processedArr));
module.exports = { formatArrayStrings, };