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
36 lines (34 sloc) 724 Bytes
<!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>