This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function longestCommonPrefix(words: string[]): string { | |
if (words.length === 0) { | |
return ""; | |
} | |
const prefixes = []; | |
const firstWord = words[0] as string; | |
for (let j = 0; j < firstWord.length; j++) { | |
const prefix = firstWord.slice(0, j); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findLongestStreak(booleans: boolean[], streakGoal: number): number { | |
const streaks: number[] = []; | |
let indexStreak = 0; | |
for (let index = 0; index < booleans.length + 1; index++) { | |
const boolean = booleans[index]; | |
if (boolean === true) { | |
streaks[indexStreak] = (streaks[indexStreak] ?? 0) + 1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use client"; | |
import { type CoinflowEnvs, CoinflowWithdraw, type SolanaWallet } from "@coinflowlabs/react"; | |
import { type Connection, PublicKey, type Transaction, type VersionedTransaction } from "@solana/web3.js"; | |
import { useEffect, useMemo, useState } from "react"; | |
// dynamic | |
import { isSolanaWallet } from "@dynamic-labs/solana"; | |
import { useDynamicContext } from "@dynamic-labs/sdk-react-core"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { stripHtml } from "string-strip-html"; | |
import { mkConfig, generateCsv, asString } from "export-to-csv"; | |
import { writeFile } from "node:fs"; | |
import { Buffer } from "node:buffer"; | |
// merge all pages (get from...) | |
const allPages = [ | |
]; | |
// parse data from all pages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hasRepeatedDigits(value: number): boolean { | |
const stringValue = String(value); | |
return new Set(stringValue).size !== stringValue.length; | |
} | |
function uniqueSum(values: number[]): number { | |
return values.reduce((accumulator, value) => hasRepeatedDigits(value) ? accumulator : accumulator + value, 0) | |
} | |
console.log(uniqueSum([1, 2, 3])) // 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given an integer array arr, return the maximum difference between two successive elements in arr's sorted form. Return 0 if there's 0 or 1 elements. | |
*/ | |
function maxGap(numbers: number[]): number { | |
if ([0, 1].includes(numbers.length)) { | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getIsEmailValid(email: string): boolean { | |
if (!email.includes('@') || !email.includes('.')) { | |
return false; | |
} | |
const parts = email.split('@'); | |
const hasMoreThanOneAtSymbol = parts.length !== 2; | |
if (hasMoreThanOneAtSymbol) { | |
return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given a number and a digit to remove from that number, | |
maximize the resulting number after the digit has been removed and print it. | |
You can choose how you want to handle a digit not existing in the number. | |
*/ | |
function removeDigit(initialNumber: number, numberToRemove: number): number { | |
const numbers: number[] = []; | |
const number = initialNumber.toString(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given a 2D array, write a function that flips it vertically or horizontally. | |
*/ | |
export function flip(matrix: number[][], direction: "horizontal" | "vertical") { | |
if (direction === "horizontal") { | |
return matrix.map((row) => row.toReversed()); | |
} | |
if (direction === "vertical") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function minSubs(integers: number[], k: number): number[] { | |
const sums = []; | |
for (let i = 0; i < integers.length; i++) { | |
if (i + k > integers.length) { | |
break; | |
} | |
let innerSum = 0; | |
const innerArray = []; |
NewerOlder