oldArray.sort((a, b) => a.id - b.id);
newArray.sort((a, b) => a.id - b.id);
oldIdx = 0;
newIdx = 0;
while (oldIdx < oldArray.length || newIdx < newArray.length) {
if (oldIdx >= oldArray.length || oldArray[oldIdx].id > newArray[newIdx].id) {
console.log(`Added id newArray[newIdx].id`);
newIdx += 1;
continue;
}
if (newIdx >= newArray.length || oldArray[oldIdx].id < newArray[newIdx].id) {
console.log(`Deleted id oldArray[oldIdx].id`);
oldIdx += 1;
continue;
}
if (oldArray[oldIdx].x !== newArray[newIdx].x) {
console.log(`Changed id newArray[newIdx].id`);
oldIdx += 1;
newIdx += 1;
}
}
const commonParts = (str1, str2, size) => {
const re = new RegExp(`.{1,${size}}`, 'g');
const arr1 = str1.match(re);
const arr2 = str2.match(re);
return arr1.filter((e, i) => arr2[i] === e);
}
commonParts('1342567', '1242566', 2); // [ "42", "56" ]
commonParts('1342567', '1242566', 3); // [ "256" ]
const position = await new Promise (
(resolve, reject) => navigator.geolocation.getCurrentPosition(
(p) => resolve(p),
(e) => reject(e),
),
);
The push() method adds one or more elements to the end of an array and returns the new length of the array.
let count = 0;
for (let z = 3; count < n; z += 1) {
for (let x = 1; x < z - 1; x += 1) {
for (let y = x + 1; y < z; y += 1) {
if (x * x + y * y === z * z) {
count += 1;
console.log(`${count}: ${x}² + ${y}² = ${z}²`);
}
}
}
}
function foo (global, factory) {
if (typeof exports === 'object' && typeof module !== 'undefined') {
module.exports = factory();
return;
}
if (typeof define === 'function' && define.amd) {
define(factory);
return;
}
global.Vue = factory();
}
foo(this, finction() { ... });