This file contains 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
export function add(...args: number[]): number { | |
return args.reduce((a, b) => a + b, 0); | |
} | |
// in-source test suites | |
if (import.meta.vitest) { | |
const { it, expect } = import.meta.vitest; | |
it("add", () => { | |
expect(add()).toBe(0); | |
expect(add(1)).toBe(1); |
This file contains 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 sum from "./sum"; | |
import { describe, expect, it } from "vitest"; | |
describe("#SUM", () => { | |
it("should return 0 for empty array", () => { | |
expect(sum()).toBe(0); | |
}); | |
it("should return 1 for [1]", () => { | |
expect(sum(1)).toBe(1); |
This file contains 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
// Purpose: Function to sum a list of numbers. | |
export default function sum(...args: number[]): number { | |
return args.reduce((a, b) => a + b, 0); | |
} |
This file contains 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 i = add_one(69); | |
println!("Hello, world! {}", i); | |
} | |
fn add_one(x: i32) -> i32 { | |
x + 1; | |
} |
This file contains 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 i = add_one(69); | |
println!("Hello, world! {}", i); | |
} | |
fn add_one(x: i32) -> i32 { | |
x + 1 | |
} |
This file contains 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 i = { | |
// This is a statement | |
let j = 69; | |
// This is an expression | |
j + 1 | |
}; | |
println!("Hello, world! {}", i); | |
} |
This file contains 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
// This code doesn't compile! | |
fn main() { | |
let x = (let y = 0); | |
} |
This file contains 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 x: i32 = 69; | |
} |
This file contains 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
app.get("/photos", async (req: Request, res: Response) => { | |
const albumId = req.query.albumId; | |
// Check the cache | |
const value = await client.get(`photos?albumId=${albumId}`); | |
if (value) { | |
console.log("Cache hit!"); | |
res.json(JSON.parse(value)); | |
} else { | |
console.log("Cache miss!"); |
This file contains 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 express, { Request, Response } from "express"; | |
import axios from "axios"; | |
const app = express(); | |
// Create Redis Client | |
import { createClient } from "redis"; | |
const client = createClient(); | |
client.on("error", (err) => console.log("Redis Client Error", err)); |