I got these 2 arrays and I would like to have a function (randomize() in this case) to be applied to each of them by calling the function and outputing the result to the console. Currently the console.log returns undefined
const array1 = ['I want to','You want to'];
let newArray1 = array1
.map(item => ({value: Math.random(), item:item}))
.sort((a,b)=> a.value-b.value)
.map(item => item.item)
.slice(0,1);
const array2 = [' eat',' sleep '];
let newArray2 = array2
.map(item => ({value: Math.random(), item:item}))
.sort((a,b)=> a.value-b.value)
.map(item => item.item)
.slice(0,1);
randomize = (x) =>{
x.map(item => ({value: Math.random(), item:item}))
.sort((a,b)=> a.value-b.value)
.map(item => item.item)
.slice(0,1);
}
randomize(array2);
console.log(randomize(array2));