Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

Use:

function isInArray(array, search)
{
return array.indexOf(search) >= 0;
}

// Usage
if(isInArray(my_array, "my_value"))
{
//...
}
4 years ago
The rand() function in returns a pseudo-random integer between 0 and RAND_MAX. You can use srand(unsigned int seed) to set a seed.

It's common practice to use the % operator in conjunction with rand() to get a different range (though bear in mind that this throws off the uniformity somewhat). For example:

/* random int between 0 and 19 */
int r = rand() % 20;
If you really care about uniformity you can do something like this:

/* Returns an integer in the range [0, n).
*
* Uses rand(), and so is affected-by/affects the same seed.
*/
int randint(int n) {
if ((n - 1) == RAND_MAX) {
return rand();
} else {
// Supporting larger values for n would requires an even more
// elaborate implementation that combines multiple calls to rand()
assert (n <= RAND_MAX)

// Chop off all of the values that would cause skew...
int end = RAND_MAX / n; // truncate skew
assert (end > 0);
end *= n;

// ... and ignore results from rand() that fall above that limit.
// (Worst case the loop condition should succeed 50% of the time,
// so we can expect to bail out of this loop pretty quickly.)
int r;
while ((r = rand()) >= end);

return r % n;
}
}
4 years ago
In some cases you may need a counter that may be provided by for-loop implementation. For that, LINQ provides ElementAt which enables the following:

for (int index = 0; index < dictionary.Count; index++) {
var item = dictionary.ElementAt(index);
var itemKey = item.Key;
var itemValue = item.Value;
}
4 years ago
don't know how you are expecting array.remove(int) to behave. There are three possibilities I can think of that you might want.

To remove an element of an array at an index i:

array.splice(i, 1);
If you want to remove every element with value number from the array:

for (var i = array.length - 1; i >= 0; i--) {
if (array[i] === number) {
array.splice(i, 1);
}
}
If you just want to make the element at index i no longer exist, but you don't want the indexes of the other elements to change:

delete array[i];
4 years ago
This worked for me:

$get("isAgeSelected ").checked == true

Where isAgeSelected is the id of the control.
4 years ago
You may also want to style textareas:

input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {
color: #636363;
}
input:-moz-placeholder, textarea:-moz-placeholder {
color: #636363;
}
4 years ago
Try, this will work out
table
{
border-collapse: collapse; /* 'cellspacing' equivalent */
}

table td, table th
{
padding: 0; /* 'cellpadding' equivalent */
}
4 years ago
Firefox 30 ignores autocomplete="off" for passwords, opting to prompt the user instead whether the password should be stored on the client. Note the following commentary from May 5, 2014:

The password manager always prompts if it wants to save a password. Passwords are not saved without permission from the user.
We are the third browser to implement this change, after IE and Chrome.
According to the Mozilla Developer Network documentation, the Boolean form element attribute autocomplete prevents form data from being cached in older browsers.

4 years ago
This should work:

$("input[name='radioName']:checked").val()
Note the "" usaged around the input:checked and not '' like the Peter J's solution
4 years ago
In my case, click event was propagating on child element. So, I had to put the following:

e.stopPropagation()

on click event:

$(document).on("click", ".remove-discount-button", function (e) {
e.stopPropagation();
//some code
});
$(document).on("click", ".current-code", function () {
$('.remove-discount-button').trigger("click");
});
Here is the html code:



4 years ago
This type of problem is caused when you use header after you write in your page. I assume you code might look like ::



title
.........



.....
header() // checking some header
?>
.....


If so, use header() before html or any kind of echo or writing code. But this is not correct solutions. You can use ob_start. This is the best solution. check this
4 years ago
You might find this command helpful to throw away local changes:

git checkout -f
And then do a cleanup (removes untracked files from the working tree):

git clean -f
If you want to remove untracked directories in addition to untracked files:

git clean -fd
4 years ago