Skip to content

Instantly share code, notes, and snippets.

@khle
Created January 14, 2022 07:45
Show Gist options
  • Save khle/eb912a883176be9e609f66fc7c2df8b9 to your computer and use it in GitHub Desktop.
Save khle/eb912a883176be9e609f66fc7c2df8b9 to your computer and use it in GitHub Desktop.
Product
import { findMatchingAndMoveToFirst } from "./findMatchingAndMoveToFirst"
interface Product{
name: string
description: string
price: number
}
function compareProducts(self: Product, other: Product): boolean {
return self.name === other.name && self.description === other.description && self.price === other.price
}
const products: Product[] = [...]
const shouldbeFirst = {
...
compare: compareProducts,
}
const reArrangedProducts = findMatchingAndMoveToFirst(products, shouldbeFirst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment