You are on page 1of 1

Coding

1. Write a function in JS which accepts 2 array parameters and should return the
output array having common items between the 2 input array?

<script>
const array1 = [4,5,10,9,8];
// const array2 = [5,10,8,9,4];
const array2 = [33,13,12,19,4];

function findCommonElement(array1, array2) {

for(let i = 0; i < array1.length; i++) {

for(let j = 0; j < array2.length; j++) {

if(array1[i] === array2[j]) {


// return console.log(array1[i]);
return true;
}
}
}

// Return if no common element exist


return false;
}
console.log(findCommonElement(array1, array2))
</script>
-------------------------------------------------

2. Write a function to create cookie with expiry date?

<script>

function cookies(){
document.cookie = "item=Pen; expires=Sat, 02 May 2023 12:00:00 UTC";

alert(document.cookie);
}
cookies();

</script>

You might also like