Skip to content
Kevin Boere edited this page Oct 17, 2023 · 22 revisions

Opdracht week 1: Dinsdag

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

Exercise 1

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();

Clone this wiki locally