-
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.
- Loading branch information
1 parent
d827bd2
commit 84f31e9
Showing
10 changed files
with
144 additions
and
54 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Gold Exchange</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.36/css/uikit.min.css" /> | ||
|
||
<script> | ||
let getInput = () => { | ||
return document.getElementById("input").value; | ||
} | ||
|
||
let setOutput = (output) => { | ||
let display = document.getElementById("output"); | ||
display.textContent = output; | ||
} | ||
|
||
let beginExchange = () => { | ||
let input = getInput(); | ||
let output = this["gold-exchange"].exchangeCoins(input); | ||
setOutput(output); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<div class="uk-container uk-text-center"> | ||
<h1 class="uk-margin-large-top uk-heading-line uk-text-center"><span>Gold Exchange</span></h1> | ||
|
||
<div class="uk-margin-large-top" uk-grid> | ||
<div class="uk-dark uk-background-muted uk-padding uk-width-2-3@s uk-width-1-2@m uk-margin-auto"> | ||
<input type="text" class="uk-input uk-text-center" id="input" oninput="beginExchange()" /> | ||
<div id="output" class="uk-margin-large-top uk-text-large uk-text-bold">0g 0e 0s 0c</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script type="text/javascript" src="gold-exchange.js"></script></body> | ||
</html> |
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,51 @@ | ||
import { Exchanger } from './gold-exchange'; | ||
|
||
let exchanger; | ||
let getExchanger = () => { | ||
if (exchanger === null || exchanger === undefined) { | ||
exchanger = new Exchanger({ rate: 1/50, newCurrency: [ | ||
{ symbol: 'g', value: 1000 }, | ||
{ symbol: 'e', value: 100 }, | ||
{ symbol: 's', value: 10 }, | ||
{ symbol: 'c', value: 1 } | ||
]}); | ||
} | ||
return exchanger; | ||
} | ||
|
||
let parseInput = (input) => { | ||
let inputCoins = new Map(); | ||
input = input.toLowerCase().split(' '); | ||
input.forEach( (i) => { | ||
let symbol = i.match(/[a-z]/); | ||
if (symbol) { | ||
let quantity = parseInt(i); | ||
if (inputCoins.has(symbol)) { | ||
inputCoins.set(symbol, inputCoins.get(symbol) + quantity); | ||
} else { | ||
inputCoins.set(symbol, quantity); | ||
} | ||
} | ||
}) | ||
let coins = []; | ||
inputCoins.forEach( (quantity, symbol) => { | ||
coins.push({ symbol: symbol[0], quantity: quantity }); | ||
}) | ||
return coins; | ||
}; | ||
|
||
let parseCoins = (coins) => { | ||
return coins.reduce( (output, coin) => { | ||
return output += `${coin.quantity}${coin.symbol} `; | ||
}, ''); | ||
} | ||
|
||
let exchangeCoins = (input) => { | ||
let coins = parseInput(input); | ||
let newCoins = getExchanger().exchange(coins); | ||
let output = parseCoins(newCoins); | ||
|
||
return output; | ||
} | ||
|
||
export { exchangeCoins }; |
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
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,9 @@ | ||
const CleanWebpackPlugin = require('clean-webpack-plugin'); | ||
const server = require('./webpack.server.js'); | ||
const merge = require('webpack-merge'); | ||
|
||
module.exports = merge(server, { | ||
plugins: [ | ||
new CleanWebpackPlugin(['docs']) | ||
] | ||
}); |
Oops, something went wrong.