-
Notifications
You must be signed in to change notification settings - Fork 0
Week 1
Kevin Boere edited this page Oct 17, 2023
·
22 revisions
The following array contains multiple data types. Normalize them by converting them all to numbers using a function and log the result in the console
|
Given Example |
My Solution |
|---|---|
const data = [
1,
2,
"3",
"4",
5
]
function convertArrayStringsToNumbers() {
/* Your code here should convert the data array to
an array containing only numbers and no strings
and log the code to the console. */
}
convertArrayStringsToNumbers(); |
const data = [
1,
2,
"3",
"4",
5
]
function convertArrayStringsToNumbers() {
/* convert the array into only numbers */
let newArray = data.map(Number);
/* log the array */
console.log(newArray);
}
convertArrayStringsToNumbers(); |
The following array contains strings with randomized capitals. You're tasked with converting all strings to lowercase with a first letter capitalized
|
Given Example |
My Solution |
|---|---|
const data = [
"robert",
"vincent",
"lAuRa",
"Cas",
"wIMER",
"rOOs"
];
/* This should the result be:
const data = [
"Robert",
"Vincent",
"Laura",
"Cas",
"Wimer",
"Roos"
];
*/
function convertArrayStringsToCapitalized() {
/* Write your functionality here and log the result */
}
convertArrayStringsToCapitalized(); |
const data = [
"robert",
"vincent",
"lAuRa",
"Cas",
"wIMER",
"rOOs"
];
function convertArrayStringsToCapitalized() {
/* Make a new array and convert first item into a upper case then the other characters should get a lower case */
const newArray = data.map(string => string.charAt(0).toUpperCase() + string.slice(1).toLowerCase());
console.log(newArray);
}
convertArrayStringsToCapitalized(); |
Wiki By Kevin Boere | Minor Information Design - Tech Track | 2023-2024