Skip to content

Instantly share code, notes, and snippets.

@khle
Created January 14, 2022 07:36
Show Gist options
  • Save khle/b7c774a0204caf3fb96443a702e93aac to your computer and use it in GitHub Desktop.
Save khle/b7c774a0204caf3fb96443a702e93aac to your computer and use it in GitHub Desktop.
Step 7
import { findMatchingAndMoveToFirst } from "./findMatchingAndMoveToFirst"
interface User {
firstName: string
lastName: string
}
function compareUsers(self: User, other: User): boolean {
return self.firstName === other.firstName && self.lastName === other.lastName
}
const users = [
{ firstName: "Jane", lastName: "Foo" },
{ firstName: "John", lastName: "Bar" },
{ firstName: "Jill", lastName: "Err" },
]
const shouldbeFirst = {
firstName: "John",
lastName: "Bar",
compare: compareUsers,
}
const reArrangedUsers = findMatchingAndMoveToFirst(users, shouldbeFirst)
console.log(reArrangedUsers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment