Skip to content
Permalink
d9d6b48878
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
34 lines (32 sloc) 718 Bytes
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title></title>
</head>
<body>
<script>
function reverseArray(array) {
var newArray = [];
for (var i = 0; i < array.length; i++) {
newArray.unshift(array[i]);
}
return newArray;
}
function reverseArrayInPlace(array) {
var temp = [];
for (var i = 0; i < Math.floor(array.length/2);i++) {
temp[i] = array[i];
array[i] = array[array.length - 1 - i];
array[array.length - 1 - i] = temp[i];
}
return array;
}
console.log(reverseArray(["A", "B", "C"]));
var arrayValue = [1, 2, 3, 4, 5];
reverseArrayInPlace(arrayValue);
console.log(arrayValue);
</script>
</body>
</html>