If you need to merge two arrays you can use the Array.concat()
function:
var array1 = [1,2,3];
var array2 = [4,5,6];
console.log(array1.concat(array2)); // [1,2,3,4,5,6];
However, this function is not the most suitable to merge large arrays because it will consume a lot of memory by creating a new array. In this case, you can use Array.push.apply(arr1, arr2)
which instead will not create a new array – it will merge the second array in the first one reducing the memory usage:
var array1 = [1,2,3];
var array2 = [4,5,6];
console.log(array1.push.apply(array1, array2)); // [1,2,3,4,5,6];
Cut and paste:
v
to select characters (or uppercase V
to select whole lines, or Ctrl-v
to select rectangular blocks).d
to cut (or y
to copy).P
to paste before the cursor, or p
to paste after.Copy and paste is performed with the same steps except for step 4 where you would press y
instead of d
:
d
stands for delete in Vim, which in other editors is usually called cut
y
stands for yank in Vim, which in other editors is usually called copy
var data = [1,2,3,4,5,6,7,1,2,3,4,5,67,8,9,4,2,3,4,5,6];
/**
* Remove Duplicates from Array
*/
function uniqArr(arr) {
var seen = {}, arr2 = [], i;
for (i = 0, len = arr.length; i < len; i++) {
if (!(arr[i] in seen)) {
arr2.push(arr[i]);
seen[arr[i]] = true;
}
}
return arr2;
}
console.log(uniqArr(data));
You may try to use MySQL Events for that:
CREATE EVENT IF NOT EXISTS `dbName`.`eventName`
ON SCHEDULE
EVERY 1 DAY // or 1 HOUR
COMMENT 'Description'
DO
BEGIN
DELETE FROM `dbName`.`TableName` WHERE `DateCol` < NOW();
END
NOTE that MySQL Event Scheduler need to be enabled on your server:
/**
* Replace all occurrences of search by replacement
*/
function replaceAll(str, search, replacement) {
return str.split(search).join(replacement);
};
Using a regular expression with the g flag set will replace all:
String.replace(/cat/g, 'dog');
The String.replace()
function allows using String and Regex to replace strings, natively this function only replaces the first occurrence. But you can simulate a replaceAll()
function by using the /g
at the end of a Regex:
Example:
var string = "john john";
console.log(string.replace(/hn/, "ana")); // "joana john"
console.log(string.replace(/hn/g, "ana")); // "joana joana"