Skip to content

Instantly share code, notes, and snippets.

@misterpoloy
Last active January 28, 2022 04:39
Show Gist options
  • Save misterpoloy/bf099dc4e7188d8be94eddcd5814dcaf to your computer and use it in GitHub Desktop.
Save misterpoloy/bf099dc4e7188d8be94eddcd5814dcaf to your computer and use it in GitHub Desktop.
Create a function `generateUrl` to generate a URL from given parameters
// 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
}
@misterpoloy
Copy link
Author

  1. 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