Skip to content

Instantly share code, notes, and snippets.

View raybellis's full-sized avatar

Ray Bellis raybellis

  • Oxfordshire, England
View GitHub Profile
@raybellis
raybellis / ArrayModalValue.swift
Created November 16, 2022 22:39
A Swift extension to find the most common (modal) value among an array of (hashable) values
extension Array where Element : Hashable {
func modalValue() -> Self.Element? {
// populate a dictionary of element vs count
var dict: [Self.Element : Int] = [:]
self.forEach { v in
if let count = dict[v] {
dict[v] = count + 1
} else {
const p1 = { x: 59197011, y: 42146958, z: 42913136384, sx: 24, sy: 470 };
const p2 = { x: 59197011, y: 21399618, z: 42913136384, sx: 254, sy: 664 };
const p3 = { x: 6735114, y: 33773393, z: 4287356928 , sx: 808, sy: 65 };
const p4 = { x: 26245172, y: 42146958, z: 4293136384, sx: 495, sy: 212 };
function project({x, y, z}) {
// use p4 as the origin
x -= p4.x;
y -= p4.y;