Ad
Code
Diff
  • // Using a regex so we can add any other characters needed also
    const regex = /^[a-zA-Z {}() \[\] ]+$/;
    
    export const validateString = (input: string, index: number) => regex.test(input.substring(index, input.length - index));
    
    • // Using a regex so we can add any other characters needed also
    • const regex = /^[a-zA-Z {}() \[\] ]+$/;
    • export const validateString = (input: string, index: number): boolean => {
    • const substr = input.substring(index, input.length - index);
    • return regex.test(substr);
    • };
    • export const validateString = (input: string, index: number) => regex.test(input.substring(index, input.length - index));
Code
Diff
  • const addArr = (arr) => arr?.length ? arr.reduce((sum, num) => sum + num, 0) : null;
    • function addArr(arr){
    • if(arr.length === 0) return null
    • let final = 0
    • arr.forEach(num => {
    • final += num
    • })
    • return final
    • }
    • const addArr = (arr) => arr?.length ? arr.reduce((sum, num) => sum + num, 0) : null;