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 array of numbers, sums the element in order. The sum is reset | |
| // exactly once during this process. The function returns the maximum sum. | |
| function maxScore(arr) { | |
| let sum = 0; | |
| let max = arr[arr.length - 1]; | |
| // for exactly one reset, i > 0 | |
| // for at most one reset, i >= 0 | |
| for (let i = arr.length - 1; i > 0; i--) { | |
| sum += arr[i]; |
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 alternates(arr) { | |
| if (arr.length <= 2) return true; | |
| let a = arr[0]; | |
| let b = arr[1]; | |
| for (let i = 2; i < arr.length; i++) { | |
| if (arr[i] != a) return false; | |
| [a, b] = [b, arr[i]]; | |
| } |
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 oddSum | |
| * @description | |
| * Identifies and returns pairs of numbers (one from array 'a' and one from array 'b') | |
| * such that the sum of the two numbers in each pair is an odd number. | |
| * | |
| * The function iterates through all possible combinations of elements from the two input arrays. | |
| * It leverages the mathematical property that the sum of an odd number and an even number | |
| * is always odd. The core logic checks if one number in the pair is odd and the other is even. | |
| * If this condition is met (meaning their sum would be odd), the pair is added to an |
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
| #!/usr/bin/env -S deno run -A --unstable-kv | |
| // This script keeps track of the last beginning letter used, and selects | |
| // a word from the colors.txt that start with the next one. It also keeps | |
| // track of the colors used so that they never come up again until the list | |
| // is completely exhausted. It keeps it's data in the Deno.KV database. | |
| const kv = await Deno.openKv(); | |
| const LAST_LETTER_KEY = "last_letter"; | |
| const USED_COLORS_KEY = "used_colors"; |
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
| #!/usr/bin/env deno run --unstable-kv --allow-read --allow-write | |
| // deno-lint-ignore-file prefer-const | |
| import { parseArgs } from "jsr:@std/cli"; | |
| let db = await Deno.openKv("~/.incr/incr.db"); | |
| if (import.meta.main) { | |
| let args = parseArgs(Deno.args, {boolean: ["list"]}); | |
| if (args["list"]) { | |
| let iter = db.list({ prefix: [] }); |
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 opentelemetry from "npm:@opentelemetry/api"; | |
| import { context, trace } from "npm:@opentelemetry/api"; | |
| import { | |
| BasicTracerProvider, | |
| BatchSpanProcessor, | |
| ConsoleSpanExporter, | |
| SimpleSpanProcessor, | |
| } from "npm:@opentelemetry/sdk-trace-base"; | |
| import { Resource } from "npm:@opentelemetry/resources"; | |
| import { OTLPTraceExporter } from "npm:@opentelemetry/exporter-trace-otlp-proto"; |
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
| fn main() { | |
| let highest = vec!["apple", "banana", "cherry", "date", "fig"] | |
| .into_iter() | |
| .map(|w| (w, score(w.to_owned()))) | |
| .reduce(|acc, b| { | |
| if b.1 > acc.1 { | |
| return b; | |
| } | |
| acc | |
| }) |
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 two strings s and t, determine if they are isomorphic. | |
| // Two strings are isomorphic if there is a one-to-one mapping | |
| // possible for every character of the first string to every | |
| // character of the second string. | |
| function isIsomorphic(a, b) { | |
| if (a.length !== b.length) return false; | |
| let mapping = {}; | |
| for (let i = 0; i < a.length; i++) { |
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
| // md-fmt takes a csv or tsv input file and outputs a formatted markdown table | |
| // with the data. | |
| package main | |
| import ( | |
| "encoding/csv" | |
| "flag" | |
| "fmt" | |
| "log" | |
| "os" |
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
| fn main() { | |
| println!("{}", validate(vec![1, 2, 3, 4, 5, 6, 7, 8, 9])); | |
| } | |
| fn validate(card: Vec<u8>) -> bool { | |
| let mut card = card; | |
| let given_check = card.pop().unwrap(); | |
| let mut check = 0; | |
| for (i, n) in card.iter().rev().enumerate() { |
NewerOlder