Skip to content

Instantly share code, notes, and snippets.

@khle
khle / product.ts
Created January 14, 2022 07:45
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
@khle
khle / step7.ts
Created January 14, 2022 07:36
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
}
@khle
khle / findMatchingAndMoveToFirst.ts
Created January 14, 2022 07:23
findMatchingAndMoveToFirst.ts
export interface Compare<T, U> {
compare: (t: T, u: U) => boolean
}
export function findMatchingAndMoveToFirst<T, U extends Compare<T, U>>(
list: readonly T[],
shouldbeFirst: U
): T[] {
return list.reduce(
(accumulator: T[], current: T) =>
@khle
khle / step6.ts
Last active January 14, 2022 06:59
Step 6
interface User {
firstName: string
lastName: string
}
function findMatchingAndMoveToFirst(
users: readonly User[],
shouldBeFirst: User
) {
return users.reduce(
@khle
khle / step5.js
Created January 14, 2022 06:51
Step 5
const users = [
{ firstName: 'Jane', lastName: 'Foo' },
{ firstName: 'John', lastName: 'Bar' },
{ firstName: 'Jill', lastName: 'Err' }
]
function findMatchingAndMoveToFirst (users, shouldBeFirst) {
return users.reduce(
(accumulator, current) =>
current.firstName === shouldBeFirst.firstName &&
@khle
khle / step4.js
Created January 14, 2022 06:47
Step 4
const users = [
{ firstName: 'Jane', lastName: 'Foo' },
{ firstName: 'John', lastName: 'Bar' },
{ firstName: 'Jill', lastName: 'Err' }
]
function findMatchingAndMoveToFirst (users, shouldBeFirst) {
return users.reduce((accumulator, current) => {
return current.firstName === shouldBeFirst.firstName &&
current.lastName === shouldBeFirst.lastName
@khle
khle / step3.js
Created January 14, 2022 06:20
Step 3
const users = [
{ firstName: 'Jane', lastName: 'Foo' },
{ firstName: 'John', lastName: 'Bar' },
{ firstName: 'Jill', lastName: 'Err' }
]
function findMatchingAndMoveToFirst (users, shouldBeFirst) {
return users.reduce((accumulator, current) => {
if (
current.firstName === shouldBeFirst.firstName &&
@khle
khle / step2.js
Created January 14, 2022 06:06
Step 2
const users = [
{ firstName: 'Jane', lastName: 'Foo' },
{ firstName: 'John', lastName: 'Bar' },
{ firstName: 'Jill', lastName: 'Err' }
]
function findMatchingAndMoveToFirst (users, shouldBeFirst) {
const reArrangedUsers = []
users.forEach(user => {
@khle
khle / step1.js
Created January 14, 2022 05:11
Step 1
const users = [
{ firstName: 'Jane', lastName: 'Foo' },
{ firstName: 'John', lastName: 'Bar' },
{ firstName: 'Jill', lastName: 'Err' }
]
function findMatchingAndMoveToFirst (users, shouldBeFirst) {
users.forEach((user, index) => {
if (
user.firstName === shouldBeFirst.firstName &&
import my.androidapp
import my.androidapp.models
suspend fun getSpaceX(limit:Int) {
val vLimit = "\$limit"
val query = """
query($vLimit:Int)
{
launchesPast(limit: $vLimit) {
mission_name