-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from glaucia86/GL/4-final-solution-exercise-no…
…dejs-debug Update and create final solutions for the 'debug Node.js apps' course
- Loading branch information
Showing
10 changed files
with
3,276 additions
and
12 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
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
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,10 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = auto | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
quote_type = single |
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,25 @@ | ||
{ | ||
"env": { | ||
"commonjs": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parser": "@babel/eslint-parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"requireConfigFile": false, | ||
"babelOptions": { | ||
"parserOpts": { | ||
"plugins": ["topLevelAwait"] | ||
} | ||
} | ||
}, | ||
"rules": { | ||
"no-console": "off", | ||
"no-undef": "off", | ||
"no-unused-vars": "off", | ||
"no-shadow": "off", | ||
"require-await": "error" | ||
} | ||
} |
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,16 @@ | ||
function fibonacci(n) { | ||
let n1 = 0; | ||
let n2 = 1; | ||
let sum = 0; | ||
|
||
for (let i = 2; i < n; i++) { | ||
sum = n1 + n2; | ||
n1 = n2; | ||
n2 = sum; | ||
} | ||
|
||
return n === 0 ? n1 : n2; | ||
} | ||
|
||
const result = fibonacci(5); | ||
console.log(result); |
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
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
45 changes: 45 additions & 0 deletions
45
nodejs-debug/6-final-solution-exercise-debug-with-vscode copy/currency.js
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,45 @@ | ||
const rates = {}; | ||
|
||
function setExchangeRate(rate, sourceCurrency, targetCurrency) { | ||
if (rates[sourceCurrency] === undefined) { | ||
rates[sourceCurrency] = {}; | ||
} | ||
|
||
if (rates[targetCurrency] === undefined) { | ||
rates[targetCurrency] = {}; | ||
} | ||
|
||
for (const currency in rates) { | ||
if (currency !== targetCurrency) { | ||
// Use a pivot rate for currencies that don't have the direct conversion rate | ||
const pivotRate = currency === sourceCurrency ? 1 : rates[currency][sourceCurrency]; | ||
rates[currency][targetCurrency] = rate * pivotRate; | ||
rates[targetCurrency][currency] = 1 / (rate * pivotRate); | ||
} | ||
} | ||
} | ||
|
||
function convertToCurrency(value, sourceCurrency, targetCurrency) { | ||
const exchangeRate = rates[sourceCurrency][targetCurrency]; | ||
return exchangeRate && value * exchangeRate; | ||
} | ||
|
||
function formatValueForDisplay(value) { | ||
return value.toFixed(2); | ||
} | ||
|
||
function printForeignValues(value, sourceCurrency) { | ||
console.info(`The value of ${value} ${sourceCurrency} is:`); | ||
|
||
for (const targetCurrency in rates) { | ||
if (targetCurrency !== sourceCurrency) { | ||
const convertedValue = convertToCurrency(value, sourceCurrency, targetCurrency); | ||
const displayValue = formatValueForDisplay(convertedValue); | ||
console.info(`- ${displayValue} ${targetCurrency}`); | ||
} | ||
} | ||
} | ||
|
||
setExchangeRate(0.88, 'USD', 'EUR'); | ||
setExchangeRate(107.4, 'USD', 'JPY'); | ||
printForeignValues(10, 'EUR'); |
Oops, something went wrong.