Skip to content

Instantly share code, notes, and snippets.

View arrlancore's full-sized avatar
🍉
On vacation

dwiki arlan arrlancore

🍉
On vacation
View GitHub Profile
@arrlancore
arrlancore / use-persisted-form.ts
Created May 17, 2024 01:09
A custom React Hook Form that persists form data to localStorage. It takes an object containing the form ID, default values, and schema as input and returns a tuple containing the form methods and a clearFormData function. The clearFormData function is used to clear the form data from localStorage. The form data is saved to localStorage whenever…
import { useEffect } from 'react';
import { DefaultValues, FieldValues, Resolver, useForm, UseFormReturn } from 'react-hook-form';
interface UsePersistedFormOptions<TFormValues extends FieldValues> {
formId: string;
defaultValues?: DefaultValues<TFormValues>;
schema?: Resolver<TFormValues>;
}
/**
@arrlancore
arrlancore / execCommand
Created March 12, 2021 15:38
ExecCommand Param
var parms = [{
"cmd": "aCommandName",
"desc": "A DOMString representing the name of the command"
}, {
"cmd": "aShowDefaultUI",
"desc": "A Boolean indicating whether the default user interface should be shown. This is not implemented in Mozilla."
}, {
"cmd": "aValueArgument",
"desc": "A DOMString representing some commands (such as insertimage) require an extra value argument (the image's url). Pass an argument of null if no argument is needed."
}];
/** ANOTHER SOLUTION AFTER EXPLORING / GOOGLE */
function standarizedString(word) {
if (typeof word === 'string') {
return word.toLowerCase().replace(/[^a-z\d]/g,'').split('').sort().join('');
}
}
function checkAnagramV2 (firstString, secondString) {
return standarizedString(firstString) === standarizedString(secondString)
}
/** ORIGINAL SOLUTION */
function countLetter(letter, words) {
const regExpLetter = new RegExp(letter, 'g');
let result = words.match(regExpLetter);
if (result) {
return result.length
}
return result;
}
function checkAnagram(firstString, secondString) {