Create a function that creates a copy of the given array and changes the last element to 'X'.
Note: The change made should not affect the original array.
function changeLastElementToX(arr){
// write your code here
}
let orig = [ 2, 5, 6, 4, 8]
let copy = changeLastElementToX(orig);
console.log(copy);
console.log(orig);
Complete the function below to change the value of bottom right corner element to 'X'.
Note: The change made should not affect the original array.
function bottomRightElementToX(arr) {
//write your code here.
}
let orig1 = [
[5, 2, 4],
[4, 1, 7],
[7, 12, 2]
]
let copy1 = bottomRightElementToX(orig1);
console.log(copy1);
console.log(orig1);
let orig2 = [
[1, 2, 3, 4],
[4, 5],
[7, 8, 9]
]
let copy2 = bottomRightElementToX(orig2);
console.log(copy2);
console.log(orig2);