IMO the right question is "Why do both type and interface exist?"
You already know why interface exists -- so you can define an object type by naming its properties e.g.
interface Point {
x: number;
y: number;
}
IMO the right question is "Why do both type and interface exist?"
You already know why interface exists -- so you can define an object type by naming its properties e.g.
interface Point {
x: number;
y: number;
}
https://leetcode.com/problems/remove-element/description/
This was interesting: I made this problem a lot harder by trying to move the "to remove" elements to the end instead of moving the "to keep" elements to the beginning.
I found my idea hard to implement iteratively, and I had to switch to recursion to get it working. After that, I was able to convert my solution to iterative -- but it would've been pretty hard to implement this approach iteratively from the start!
| km | mi (est.) | mi (act.) | error | |
| ----------------------------------- | |
| 1 | 1 | 0.62 | 60.9% | |
| 2 | 1 | 1.24 | -19.5% | |
| 3 | 2 | 1.86 | 7.3% | |
| 5 | 3 | 3.11 | -3.4% | |
| 8 | 5 | 4.97 | 0.6% | |
| 13 | 8 | 8.08 | -1.0% | |
| 21 | 13 | 13.05 | -0.4% | |
| 34 | 21 | 21.13 | -0.6% |
| import re | |
| def sscanf(s, fmt): | |
| ''' | |
| Parses the string against the given template, returning the values of the | |
| slots. If no match, return None. | |
| The string must be a full match (like re.fullmatch()). |
| class Draggable { | |
| private element: HTMLElement; | |
| private currentDrag: undefined | { | |
| initialMouseX: number, | |
| initialMouseY: number, | |
| initialElementX: number, | |
| initialElementY: number, | |
| removeListeners: () => void, | |
| }; |
| import math | |
| class Line: | |
| def __init__(self, m, b): | |
| self.m = m | |
| self.b = b | |
| def __call__(self, x): | |
| return self.m * x + self.b |
https://github.com/prendradjaja/advent-of-code-2021/blob/main/20--trench-map/a.py
def step(self, rules):
self.pixels = use self, rules:
new_pixels = [[None] * self.outer_width for _ in range(self.outer_height)]
for r, row in enumerate(self.pixels):
for c, _ in enumerate(row):
neighborhood_value = self.neighborhood_value((r, c))
new_pixels[r][c] = rules[neighborhood_value]