Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add files via upload
  • Loading branch information
kyh16103 committed Mar 2, 2020
1 parent 908a757 commit 2f11452
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
36 changes: 36 additions & 0 deletions index-2.html
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title></title>
</head>
<body>
<script>
function range(start, end, step = start <= end ? 1 : -1) {
let result = [];
for (let i = start; step >= 0 ? i <= end : i >= end; i+=step) {
result.push(i);
}
return result;
}

function sum(numbers) {
result = 0;
for (let num of numbers) {
result += num;
}
return result;
}

console.log(range(1, 10));
console.log(range(1, 10, 2));
console.log(range(5, 2, -1));
console.log(range(5, 2));
console.log(range(10, 1, -3));
console.log(sum(range(1, 10)));
console.log(sum(range(1, 10, 2)));
console.log(sum(range(10, 1, -3)));
</script>
</body>
</html>
34 changes: 34 additions & 0 deletions reversingarray.html
@@ -0,0 +1,34 @@
<!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>

0 comments on commit 2f11452

Please sign in to comment.