Last active
January 28, 2022 04:39
-
-
Save misterpoloy/bf099dc4e7188d8be94eddcd5814dcaf to your computer and use it in GitHub Desktop.
Create a function `generateUrl` to generate a URL from given parameters
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
// exercise 2 | |
const payload = { | |
width: 360, | |
height: 300, | |
locale: 'en', | |
toolbar_bg: '', | |
interval: '3h', | |
pair: 'BTC_USD', | |
} | |
let URL = "http://testurl.bitfinx.com/" | |
const getURL = (data) => { | |
const params = Object.keys(data) | |
.filter(param => data[param]) | |
.map(key => `${key}=${data[key]}`) | |
.join('&') | |
return `${URL}?${params}` | |
} | |
console.log(getURL(payload)) | |
// Excersie 3 | |
const volumeSetup = () => { | |
// I'm not sure if this part works at all, I'm assuming is part of the demo | |
const volumeUnit = window.APP.util.getSettings('ticker_vol_unit').toUpperCase(); | |
// Since we're using a patter convention maybe a more adaptble way would be to use the sufix as a identifier | |
// Easier to read and maintain | |
$(`#tickervolccy_${volumeUnit === 'FIRSTCCY' ? 0 : volumeUnit}`).prop("checked", true); | |
// override currencies list | |
var result = window.APP.util.initCurrenciesList() | |
return result | |
} |
- Apply some refactoring to improve the code of the following function. Explain the reasons behind your changes and which benefit they bring into the code.
var volumeSetup = function () {
// setup volume unit interface
var volumeUnit = window.APP.util.getSettings('ticker_vol_unit').toUpperCase();
var element = null;
if (volumeUnit === 'FIRSTCCY') {
element = $('#tickervolccy_0');
} else if (volumeUnit === 'USD') {
element = $('#tickervolccy_USD');
} else if (volumeUnit === 'BTC') {
element = $('#tickervolccy_BTC');
} else if (volumeUnit === 'ETH') {
element = $('#tickervolccy_ETH');
}
if (element) {
element.prop("checked", true);
}
// override currencies list
var result = window.APP.util.initCurrenciesList()
return result
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
generateUrl
to generate a URL from given parameters:{
width: 360,
height: 300,
locale: 'en',
toolbar_bg: '',
interval: '3h',
pair: 'BTC_USD',
}
You can use any lib but the generated result should be
"http://testurl.bitfinx.com/?height=300&interval=3h&locale=en&pair=BTC_USD&width=360"
More parameters are planned to be added/removed later and the the result should neglect the empty params (ex: should not include toolbar_bg in URL when its value is empty).