forked from r-argentina-programa/introduccion-a-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solutions up to r-argentina-programa#10 out of r-argentina-programa#53 …
…algorithms
- Loading branch information
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
Desafío de programación #10: Calcula la suma de todos los números en un array de números | ||
*/ | ||
|
||
function addArray(arr) { | ||
let result = 0; | ||
for (let i = 0; i < arr.length; i++) { | ||
result += arr[i]; | ||
} | ||
console.log(result); | ||
} | ||
|
||
addArray([100, 22, 43, 64, 15, 86, 70, 78, 19, 34]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
Desafío de programación #6: Calcula 10! (10 factorial) | ||
10 * 9 * 8 * ... * 1 | ||
*/ | ||
|
||
function calculatesTenFactorial(num = 10) { | ||
let result = 1; | ||
for (let i = 2; i <= num; i++) { | ||
result *= i; | ||
} | ||
console.log(result); | ||
} | ||
|
||
calculatesTenFactorial(); // Also works for any other number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
Desafío de programación #7: Calcula la suma de todos los números impares mayores que 10 y menores que 30 | ||
*/ | ||
|
||
function addOddNumbersBetweenTenAndThirty() { | ||
let result = 0; | ||
for (let i = 11; i < 30; i += 2) { | ||
result += i; | ||
} | ||
console.log(result); | ||
} | ||
|
||
addOddNumbersBetweenTenAndThirty(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
Desafío de programación #8: Crea una función que convierta de Celsius a Fahrenheit | ||
*/ | ||
|
||
function fromCelsiusToFahrenheit(celsius) { | ||
let fahrenheit; | ||
const numberA = 9 / 5; | ||
const numberB = 32; | ||
fahrenheit = Number((celsius * numberA + numberB).toFixed(1)); | ||
console.log(celsius + '°C equals to ' + fahrenheit + '°F'); | ||
} | ||
|
||
fromCelsiusToFahrenheit(36); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
Desafío de programación #9: Crea una función que convierta de Fahrenheit a Celsius | ||
*/ | ||
|
||
function fromFahrenheitToCelsius(fahrenheit) { | ||
let celsius; | ||
const numberA = 32; | ||
const numberB = 5 / 9; | ||
celsius = Number(((fahrenheit - numberA) * numberB).toFixed(1)); | ||
console.log(fahrenheit + '°F equals to ' + celsius + '°C'); | ||
} | ||
|
||
fromFahrenheitToCelsius(32); |