|
I hope that this is the most terrifying thing that I read all day.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
|
You might actually be insane.
Send me your credit card and I'll happily send you the code.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
he is not aware of the forum
|
|
|
|
|
suggest me to how to code the calculation of
working hours in Week excluding Weekends(saturday and sunday) in JavaScript or jquery using Moment.js
|
|
|
|
|
|
I'm fiddling around setTimeOut javascript function. I've 5 function calls with different time delay. What I want is to execute only those functions which have a 500ms delay difference between each functions. I've created a fiddle (https://jsfiddle.net/vt7sanav/). Can someone suggest what should i do to check the delay between two functions is 500ms then execute the function else ignore the function.
Example: Packet1 comes in, should be sent(printed) straight away, Wait 500ms and within 500ms, ignore new msgs(function calls). Print only messages which have a delay of 500ms in between.
function postMessage(msg) {
$("#msgBox").append("\n" + msg + " time:" + new Date().getSeconds() + ":" + new Date().getMilliseconds());
}
function makeRequest(msg) {
postMessage(msg);
}
function makeRequestThrottled(msg) {
postMessage(msg);
}
function sendMessage(msg, delay) {
setTimeout(() =>
makeRequestThrottled(msg), delay);
}
sendMessage("Packet1", 200);
sendMessage("Packet2", 600);
sendMessage("Packet3", 1800);
sendMessage("Packet4", 2400);
sendMessage("Packet5", 2600);
|
|
|
|
|
try
function sendMessage(name, delay) {
console.log(name, delay);
}
var packetInfo = [{ name: 'Packet1', delay: 200 },
{ name: 'Packet2', delay: 600 },
{ name: 'Packet3', delay: 1800 },
{ name: 'Packet4', delay: 2400 },
{ name: 'Packet5', delay: 2600 }];
var prev = undefined;
for (var i = 0; i < packetInfo.length; i++) {
var item = packetInfo[i];
if (i == 0)
sendMessage(item.name, item.delay);
else {
if( item.delay - prev.delay > 500 )
sendMessage(item.name, item.delay);
}
prev = item;
}
|
|
|
|
|
I need to parse a JSON in javascript.
This works fine if the JSON is like:
{"test":[{"data":{" ...
where I can access the data like (if arg was "receiveddata" in the callback function)
recieveddata.test[index].data ...
but know I'm in the case where I have this:
{"1":[{"data":{"date_of //notice the "1" as key
There is no way I can access the data like above as receiveddata.1[index].data ...
How can I access the data? (or should I ask the source to update their key names)
(I'm using the jQuery getJSON function, which works fine on other JSON's where there are normal keys.)
thanks.
|
|
|
|
|
What happens in JavaScript is that everything is possible, even the impossible.
{
"1" :
[
{
"field": "value"...
You can access properties in the JavaScript through index notation as well, this is one of the funniest things in JavaScript. This makes it possible to have properties, and attributes in a way that is impossible in other languages directly. JavaScript supports, object.property , object["property"] and much more ways to access the properties, and attach the properties. Thus, when you have a property called (for instance), "object.1 ", or "object.something-else ", then you can access them through index notation and that would be valid JavaScript.
So I am unsure as to what your JSON is like but if the JSON schema is like the following — which indeed is like yours,
var str = "{ \"1\": [{\"field\": \"attr\"}]}";
Then you can execute the following JavaScript and do what you intent to,
var obj = JSON.parse(str);
alert(obj["1"][0].field);
Try this, and you will see how strange sometimes JavaScript can be. Try the code online here, [Edit fiddle - JSFiddle](https://jsfiddle.net/afzaal_ahmad_zeeshan/mvbtztpL/)
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Do you believe it, I was actually thinking about this solution and I dismissed it!
(I was not able to get it through normal index, so I dismissed a key index, because usually if key index is possible, so is normal indexing)
anyway got it up and running, thanks for pointing it out
|
|
|
|
|
Hi I want to know how to hide developer tool option from setting in chrome, f 12 button , and right click inspect element option .i will be grateful if i will get a reply asap.
|
|
|
|
|
You can't. If access to dev tools is harmful to your site then change your site so that it's not.
|
|
|
|
|
Guys, what do you think about Google Policy with Angular releases? Just half of a year - and we'll got Angular 6 version. Is it too fast or it's ok?
|
|
|
|
|
I think it's awful, and I stopped using Angular in part because of that.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
|
Jeremy Falcon
|
|
|
|
|
var home = function() {
var count = 0;
var morningwork = function() {
console.log("Morning work");
count++;
};
var eveningwork = function() {
console.log("Evening work");
count++;
};
var caller = function() {
return {
job1: morningwork,
job2: eveningwork
};
};
return {
caller: caller,
count: count
};
};
var home = home();
home.caller().job1();
home.caller().job2();
home.caller().job1();
console.log(home.count);
|
|
|
|
|
Because the return statement at the end of the home function creates a copy of the value of the count variable at the point where the method returns. There is no connection between that copy and the local variable, so when the "work" functions update the local variable, that change is not reflected in the returned object.
Imagine how difficult it would be to write code in a language where that was not the case!
var x = 42;
var y = x;
x = 0;
You'll need to change the returned object so that count is a function that returns the current value of the local variable:
var home = function() {
...
return {
caller: caller,
count: function(){
return count;
}
};
};
var h = home();
h.caller().job1();
h.caller().job2();
h.caller().job1();
console.log(h.count());
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
There is a bug somewhere in this function and I can't find where. Please advise.
function verifyCrops() {
try {
for(var i = 0; i < 7; i++) {
if (cropsFieldset.getElementsByTagName("input")[i].
checked) {
cropsComplete = true;
messageElement.innerHTML = "";
testFormCompleteness();
i = 8;
}
}
if (i === 7) {
throw "Please select at least one crop."
}
}
catch(message) {
cropsComplete = false;
messageHeadElement.innerHTML = ""
messageElement.innerHTML = message;
}
}
modified 3-Oct-17 23:26pm.
|
|
|
|
|
Dunno, but it's poor form to catch what you throw yourself.
|
|
|
|
|
Jason Lemon wrote: There is a bug somewhere in this function How do you know?
|
|
|
|
|
Place a debugger and execute line by line and see in which line the error is being thrown
|
|
|
|
|
How could we possibly know? We don't know what the code is supposed to do nor can we run it. We don't even have all of the code. Is this a joke or did you really expect someone to be able to tell you?
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Please let us know what the function is expected to do, and what it does not!
|
|
|
|