Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercises day3 5 #9

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added src/week1/day0/formHTML.html
Empty file.
17 changes: 17 additions & 0 deletions src/week1/day0/listHTML.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My to do list</title>
</head>
<body>
<h1>To do items</h1>

<ul>
<li>Estudiar</li>
<li>Ordenar la pieza</li>
<li>Ir al gim</li>
<li>Ir al trabajo</li>
</ul>
</body>
</html>
66 changes: 66 additions & 0 deletions src/week1/day0/tableHTML.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My to do list</title>
<style>
body {
background: #ffffff;
margin: 0;
padding: 20px;
line-height: 1.4em;
font-family: tahoma, arial, sans-serif;
font-size: 62.5%;
}

table {
width: 80%;
margin: 0;
background: #FFFFFF;
border: 1px solid #333333;
border-collapse: collapse;
}

td, th {
border-bottom: 1px solid #333333;
padding: 6px 16px;
text-align: left;
}

th {
background: #EEEEEE;
font-size: 85%;
}

caption {
background: #E0E0E0;
margin: 0;
border: 1px solid #333333;
border-bottom: none;
padding: 6px 16px;
font-weight: bold;
}
</style>
</head>
<body>
<table>
<caption>To do items</caption>
<tr>
<th>Gasto</th>
<th>$$</th>
</tr>
<tr>
<td>Mt. Lassen</td>
<td>California</td>
</tr>
<tr>
<td>Mt. Hood</td>
<td>Oregon</td>
</tr>
<tr>
<td>1980</td>
<td>Explosive Eruption</td>
</tr>
</table>
</body>
</html>
14 changes: 14 additions & 0 deletions src/week1/days2-5/beanCounting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function countChar(string, ch) {
let cont = 0;
for (let i = 0; i < string.length; i++) {
if (string[i] == ch) {
cont += 1;
}
}
return cont;
}

function countBs(string) {
return countChar(string, "B");
}

14 changes: 14 additions & 0 deletions src/week1/days2-5/chessboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
let salida = "";

for (let y = 0; y < 9; y++) {
for (let x = 0; x < 9; x++) {
if ((x + y) % 2 == 0) {
salida += " ";
} else {
salida += "#";
}
}
salida += "\n";
}

console.log(salida);
24 changes: 24 additions & 0 deletions src/week1/days2-5/deepComparison.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function deepEqual(a, b) {
if (a === b)
return true;

if (a == null || typeof a != "object" ||
b == null || typeof b != "object") {
return false;
}

let keysA = Object.keys(a), keysB = Object.keys(b);

if (keysA.length != keysB.length) {
return false;
}

for (let key of keysA) {
if (!keysB.includes(key) || !deepEqual(a[key], b[key])) {
return false;
}
}

return true;
}

10 changes: 10 additions & 0 deletions src/week1/days2-5/exercise.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="loopingTriangle.js"></script>
</head>
<body>
<h1>JavaScript</h1>
</body>
</html>
9 changes: 9 additions & 0 deletions src/week1/days2-5/fizzBuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
for (let n = 1; n <= 100; n++) {
let salida = "";
if (n % 3 == 0)
salida += "Fizz";
if (n % 5 == 0)
salida += "Buzz";
console.log(salida || n);
}

30 changes: 30 additions & 0 deletions src/week1/days2-5/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function arrayToList(array) {
let list = null;
for (let i = array.length - 1; i >= 0; i--) {
list = {value: array[i], rest: list};
}
return list;
}

function listToArray(list) {
let array = [];
for (let node = list; node; node = node.rest) {
array.push(node.value);
}
return array;
}

function prepend(value, list) {
return {value, rest: list};
}

function nth(list, n) {
if (!list)
return undefined;
else
if (n == 0)
return list.value;
else
return nth(list.rest, n - 1);
}

2 changes: 2 additions & 0 deletions src/week1/days2-5/loopingTriangle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
for(let hash = "#"; hash.length < 8; hash += "#")
console.log(hash);
6 changes: 6 additions & 0 deletions src/week1/days2-5/minimum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function min(a, b){
if(a<b)
return a;
else
return b;
}
13 changes: 13 additions & 0 deletions src/week1/days2-5/recursion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function isEven(n) {
if (n == 0)
return true;
else
if (n == 1)
return false;
else
if (n < 0)
return isEven(-n);
else
return isEven(n - 2);
}

17 changes: 17 additions & 0 deletions src/week1/days2-5/reverseArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function reverseArray(array) {
let salida = [];
for (let i = array.length - 1; i >= 0; i--) {
salida.push(array[i]);
}
return salida;
}

function reverseArrayInPlace(array) {
for (let i = 0; i < Math.floor(array.length / 2); i++) {
let old = array[i];
array[i] = array[array.length - 1 - i];
array[array.length - 1 - i] = old;
}
return array;
}

27 changes: 27 additions & 0 deletions src/week1/days2-5/sumRange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function range(start, end, step) {
let array = [];

if( start < end ){
step = 1;
}
else{
step = -1;
}

if (step > 0) {
for (let i = start; i <= end; i += step)
array.push(i);
}
else {
for (let i = start; i >= end; i += step) array.push(i);
}
return array;
}

function sum(array) {
let total = 0;
for (let value of array) {
total += value;
}
return total;
}