After receiving GET
request, return to the user his public ip, not using any third-party service (it can be received from request headers, google how)
Response type, structure, etc at your own discretion
After receiving GET
request, return to the user his public ip, not using any third-party service (it can be received from request headers, google how)
Response type, structure, etc at your own discretion
Useful links:
const benchmark = (func, input, iterations) => { | |
const start = performance.now() | |
for (let i = 0; i < iterations; i++) { | |
func(...input) | |
} | |
const finish = performance.now() | |
const time = finish - start | |
return { | |
time, | |
aproxOperation: (time/iterations) |
function groupSkip(arr, shift, skip = 1) { | |
const res = [] | |
let limit = 0 | |
while (limit+shift <= arr.length) { | |
res.push(arr.slice(limit, shift + limit - skip)) | |
limit += shift | |
} | |
return res | |
} |
const getImageDataFromUrl = (url, callback) => { | |
const canvas = document.createElement("canvas") | |
const context = canvas.getContext("2d") | |
const image = new Image() | |
image.onload = async () => { | |
const { width, height } = image | |
const { data: imageData } = context.getImageData(0, 0, width, height) | |
callback(imageData) |
let range = { | |
from: 1, | |
to: 5, | |
[Symbol.asyncIterator]() { | |
return { | |
current: this.from, | |
last: this.to, | |
async next() { |
const withResource = async (fn) => { | |
const instance = await getInstance() | |
try { | |
return await fn(instance) | |
} finally { | |
await instance.close() | |
} | |
} | |
const task = await witchResource(async (instance) => { |
/* | |
Example: | |
const arr = [1,2,3,4,5,7,8] | |
arr.subarrayFromIndexes([0,77,3,5,15]) | |
*/ | |
Array.prototype.subarrayFromIndexes = function (indexes) { | |
if (!Array.isArray(this)) | |
throw "indexes must be array" | |
return indexes.reduce((acc, current) => { |
/* | |
const toCurryFn = (...args) => {...} | |
const curried = curry(toCurryFn); | |
... | |
*/ | |
function curry(fn) { | |
const argumentsArray = []; | |
function subCurry(...args) { |
/* | |
Just experiments and some thoughts. | |
Better use for/foreach over arrays and check if target arr already contains objects, something like: | |
const target = [...one] | |
for (current of two) { | |
const duplicated = target.find(item => item.id === current.id); | |
!duplicated && target.push(current); |