A general chat about JavaScript. Ask anything you like or share your best cat picture. Please check Google/StackOverflow for answers before asking for help. And remember, be nice! Don't ask to ask, just ask
$(".pop").popover({ trigger: "manual" , html: true, animation:false})
.on("mouseenter", function () {
var _this = this;
$(this).popover("show");
$(".popover").on("mouseleave", function () {
$(_this).popover('hide');
});
}).on("mouseleave", function () {
var _this = this;
setTimeout(function () {
if (!$(".popover:hover").length) {
$(_this).popover("hide");
}
}, 300);
});
arr.length % arr.length
returns 0, so, on the last array element your next receives value from the first element of array.
Hi all
I'm running into a problem with recordrtc.
After recording the audio from my platfrom using recordrtc its been saved temporarily to /tmp folder. But in some scenario the audio file is missing or /tmp/upload_b6460cdff8c889265b0b063712f46c10: Invalid data found when processing input.
Can anyone explain this scenario?
Thanks in advance
//function checkCashRegister houses the major global variables and conditions to be met
//function findChange searches for exact change to be returned
//function totalCid calculates the total number of change in the drawer
//'cid' stands for cash in drawer
//'theAvailable' refers to total number of available change in the drawer
function totalCid(cid) {
let total = 0;
for (let piece of cid ) {
total += piece[1];
}
return total.toFixed(2);
};
//exact change
function findChange(moneyOwed, cid) {
var change_arr = [];
var currencyValues = {
'ONE HUNDRED': 100.00,
'TWENTY': 20.00,
'TEN': 10.00,
'FIVE': 5.00,
'ONE': 1.00,
'QUARTER': 0.25,
'DIME': 0.10,
'NICKEL': 0.05,
'PENNY': 0.01
};
for (let i = cid.length - 1; i >= 0; i--) {
const currName = cid[i][0];
const currTotal = cid[i][1];
const currValue = currencyValues[currName];
let currAmount = (currTotal/currValue).toFixed(2);
let currToReturn = 0;
while (moneyOwed >= currValue && currAmount > 0) {
moneyOwed -= currValue;
moneyOwed = moneyOwed.toFixed(2);
currAmount --;
currToReturn ++;
}
if (currToReturn > 0) {
change_arr.push([currName, currToReturn * currValue]);
}
}
return change_arr
};
function checkCashRegister (price, cash, cid) {
var register = {'status' : null, 'change' : []};
const moneyOwed = parseFloat(cash - price).toFixed(2);
const theAvailable = totalCid(cid);
if (Number(moneyOwed) > Number(theAvailable)) {
register.status = 'INSUFFICIENT_FUNDS';
return register;
};
if (Number(moneyOwed) === Number(theAvailable)) {
register.status = 'CLOSED';
register.change = [...cid];
return register;
};
register.change = findChange(moneyOwed, cid);
if (Number(moneyOwed) < Number(theAvailable)) {
register.status = 'OPEN';
return register
} return {status : "INSUFFICIENT_FUNDS"};
}
//function checkCashRegister houses the major global variables and conditions to be met
//function findChange searches for exact change to be returned
//function totalCid calculates the total number of change in the drawer
//'cid' stands for cash in drawer
//'theAvailable' refers to total number of available change in the drawer
function totalCid(cid) {
let total = 0;
for (let piece of cid ) {
total += piece[1];
}
return total.toFixed(2);
};
function checkCashRegister (price, cash, cid) {
var register = {'status' : null, 'change' : []};
const moneyOwed = parseFloat(cash - price).toFixed(2);
const theAvailable = totalCid(cid);
if (Number(moneyOwed) > Number(theAvailable)) {
register.status = 'INSUFFICIENT_FUNDS';
return register;
};
if (Number(moneyOwed) === Number(theAvailable)) {
register.status = 'CLOSED';
register.change = [...cid];
return register;
};
register.change = findChange(moneyOwed, cid);
if (moneyOwed > totalCid(register.change)) {
register.status = 'INSUFFICIENT_FUNDS';
register.change = []
return register;
};
if (Number(moneyOwed) < Number(theAvailable)) {
register.status = 'OPEN';
return register
};
};
//exact change
function findChange(moneyOwed, cid) {
var change_arr = [];
var currencyValues = {
'ONE HUNDRED': 100.00,
'TWENTY': 20.00,
'TEN': 10.00,
'FIVE': 5.00,
'ONE': 1.00,
'QUARTER': 0.25,
'DIME': 0.10,
'NICKEL': 0.05,
'PENNY': 0.01
};
//looping through the drawer for cash
for (let i = cid.length - 1; i >= 0; i--) {
const currName = cid[i][0];
const currTotal = cid[i][1];
const currValue = currencyValues[currName];
let currAmount = (currTotal/currValue).toFixed(2);
let currToReturn = 0;
//selecting the right bill value to return
while (moneyOwed >= currValue && currAmount > 0) {
moneyOwed -= currValue;
moneyOwed = moneyOwed.toFixed(2);
currAmount --;
currToReturn ++;
}
if (currToReturn > 0) {
change_arr.push([currName, currToReturn * currValue]);
}
}
return change_arr
};
let score = ab.reduce((memo, item) => memo *= item.weight * item.answer, 1);
Hi. I needed your thoughts on the use of constants as in the code below.
function createUrl(urlPath) {
const endpoint = url.parse(env.config.get('myEndpoint'));
endpoint.pathname = path.posix.join(endpoint.pathname, urlPath);
return endpoint;
}
The above snippet won't throw an error but is it okay to declare some object as a const even if I know that I would be making some change to it?