Signup/Sign In

Answers

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

This is by far the easiest way to get exactly the result you are looking for, using jQuery:
***var diff = $(old_array).not(new_array).get();***
**diff** now contains what was in **old_array** that is not in **new_array**
4 years ago
Found an elegant way from MDN
***
var vegetables = ['parsnip', 'potato'];
var moreVegs = ['celery', 'beetroot'];

// Merge the second array into the first one
// Equivalent to vegetables.push('celery', 'beetroot');
Array.prototype.push.apply(vegetables, moreVegs);

console.log(vegetables); // ['parsnip', 'potato', 'celery', 'beetroot']
***
Or you can use the **spread operator** feature of ES6:

***let fruits = [ 'apple', 'banana'];
const moreFruits = [ 'orange', 'plum' ];

fruits.push(...moreFruits); // ["apple", "banana", "orange", "plum"]***
4 years ago
Use underscore (or loDash :)):
***var randomArray = [
'#cc0000','#00cc00', '#0000cc'
];

// use _.sample
var randomElement = _.sample(randomArray);

// manually use _.random
var randomElement = randomArray[_.random(randomArray.length-1)];
***
Or to shuffle an entire array:
***
// use underscore's shuffle function
var firstRandomElement = _.shuffle(randomArray)[0];
***
4 years ago
This can be a global function or a method of a custom object, if you aren't allowed to add to native prototypes. It removes all of the items from the array that match any of the arguments.
***Array.prototype.remove = function() {
var what, a = arguments, L = a.length, ax;
while (L && this.length) {
what = a[--L];
while ((ax = this.indexOf(what)) !== -1) {
this.splice(ax, 1);
}
}
return this;
};

var ary = ['three', 'seven', 'eleven'];

ary.remove('seven');

/* returned value: (Array)
three,eleven
*/

***
To make it a global-

***function removeA(arr) {
var what, a = arguments, L = a.length, ax;
while (L > 1 && arr.length) {
what = a[--L];
while ((ax= arr.indexOf(what)) !== -1) {
arr.splice(ax, 1);
}
}
return arr;
}
var ary = ['three', 'seven', 'eleven'];
removeA(ary, 'seven');


/* returned value: (Array)
three,eleven
*/

***
And to take care of IE8 and below-

***if(!Array.prototype.indexOf) {
Array.prototype.indexOf = function(what, i) {
i = i || 0;
var L = this.length;
while (i < L) {
if(this[i] === what) return i;
++i;
}
return -1;
};
}***
4 years ago
It works for characters and numbers, going forwards or backwards with an optional step.
***var range = function(start, end, step) {
var range = [];
var typeofStart = typeof start;
var typeofEnd = typeof end;

if (step === 0) {
throw TypeError("Step cannot be zero.");
}

if (typeofStart == "undefined" || typeofEnd == "undefined") {
throw TypeError("Must pass start and end arguments.");
} else if (typeofStart != typeofEnd) {
throw TypeError("Start and end arguments must be of same type.");
}

typeof step == "undefined" && (step = 1);

if (end < start) {
step = -step;
}

if (typeofStart == "number") {

while (step > 0 ? end >= start : end <= start) {
range.push(start);
start += step;
}

} else if (typeofStart == "string") {

if (start.length != 1 || end.length != 1) {
throw TypeError("Only strings with one character are supported.");
}

start = start.charCodeAt(0);
end = end.charCodeAt(0);

while (step > 0 ? end >= start : end <= start) {
range.push(String.fromCharCode(start));
start += step;
}

} else {
throw TypeError("Only string and number types are supported");
}

return range;

}***
4 years ago
Preferably put in a Util.java class
***public static float dpFromPx(final Context context, final float px) {
return px / context.getResources().getDisplayMetrics().density;
}

public static float pxFromDp(final Context context, final float dp) {
return dp * context.getResources().getDisplayMetrics().density;
}***
4 years ago
From **adb --help**:
***connect : - Connect to a device via TCP/IP***
That's a command-line option by the way.
You should try connecting the phone to your Wi-Fi, and then get its IP address from your router. It's not going to work on the cell network.
The port is 5554.
4 years ago
Add this **android:screenOrientation="portrait"** in your manifest file where you declare your activity like this
*** ....
android:screenOrientation="portrait" />
***
If you want to do using java code try
***setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ***
before you call **setContentView** method for your activity in **onCreate()**.
Hope this help and easily understandable for all...
4 years ago
If you have recently installed Java 8 and uninstalled Java 7, install JDK 8 and retry.
4 years ago
***public static Bitmap drawableToBitmap (Drawable drawable) {
Bitmap bitmap = null;

if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if(bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}

if(drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Single color bitmap will be created of 1x1 pixel
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
}

Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
***
4 years ago
try this one:
***var box = document.getElementById('aioConceptName');
conceptName = box.options[box.selectedIndex].text;***
4 years ago
Try this :
***function getURL(url){
return $.ajax({
type: "GET",
url: url,
cache: false,
async: false
}).responseText;
}
//example use
var msg=getURL("message.php");
alert(msg);***
4 years ago