Skip to content

Instantly share code, notes, and snippets.

interface FormatDate extends Date {
format(this: Date, locale?: string): Date | string;
isSameDate(this: Date, value: any): boolean;
isBefore(this: Date, value: any): boolean;
isSameDateOrBefore(this: Date, value: any): boolean;
}
export const isValidDate = (value: any) => {
return String(new Date(value)) !== 'Invalid Date';
};
/**
* @param {number[]} nums - numbers list
* @param {number} num - desired number
* @return {null | number}
*/
function binarySearch(nums, num) {
let left = 0
let middle;
let right = nums.length - 1;
function containsDuplicate(nums) {
const numbersList = {};
for (const number of nums) {
if (!numbersList[number]) {
numbersList[number] = true;
} else {
return true;
}
}
function generate(numRows: number) {
const result = [];
for (let i = 0; i < numRows; i++) {
result[i] = [];
for (let j = 0; j <= i; j++) {
if (
!Array.isArray(result[i - 1]) ||
!result[i - 1][j - 1] ||
function solution(n) {
const binaryNumber = Number(n).toString(2);
function findAllOnes(i = 0, res = []) {
const index = binaryNumber.indexOf('1', i);
return index > -1
? findAllOnes(index + 1, res.concat(index))
: res;
}
const response1 = {
data: {
users: [
{},
{
name: 'Oliver',
surname: 'Max',
},
],
},
// We need to sum big numbers and we require your help.
// Write a function that returns the sum of two numbers. The input numbers are strings and the function must return a string.
// Example
// add("123", "321"); -> "444"
// add("11", "99"); -> "110"
// Notes
// The input numbers are big.
// The input is a string of only digits
@OliverMax
OliverMax / AppImage.vue
Created October 21, 2021 14:31
load images with cache
<template>
<picture data-vue-component-name="AppImage">
<source
v-if="webp"
:srcset="cachedImages[webp]"
type="image/webp"
>
<img
v-if="png"
@OliverMax
OliverMax / v-hover-3d.js
Last active July 6, 2023 09:58
v-hover-3d
function init(nodeEl, bindings) {
if (bindings.isEnabled) {
saveBindings.call(nodeEl, bindings);
nodeEl.onmousemove = onMouseMove;
nodeEl.onmouseleave = onMouseLeave;
}
}
function onMouseMove({ offsetX, offsetY }) {
const validateRange = (current, min, max) => Math
.min(
Math.max(current, min),
max,
);
const transformto16 = (num) => {
const transformed = validateRange(num, 0, 255)
.toString(16)
.toUpperCase();