Skip to content

Instantly share code, notes, and snippets.

View sweko's full-sized avatar

Wekoslav Stefanovski sweko

View GitHub Profile
type Maybe<T> = T|undefined;
function generateCompareArray<T, U>(first: T[], second: T[],
keyExtractor: (item: T) => U,
keyComparer: (first: U, second: U) => number
): {first: Maybe<T>, second: Maybe<T>}[] {
const fschwartz = first.map(item => ({item, key: keyExtractor(item)}));
fschwartz.sort((a, b) => keyComparer(a.key, b.key));
const sschwartz = second.map(item => ({item, key: keyExtractor(item)}));
sschwartz.sort((a, b) => keyComparer(a.key, b.key));
@sweko
sweko / Umcn.cs
Last active July 15, 2020 20:45 — forked from mnikolovski/Umcn.cs
Represents a Unique Master Citizen Number class(Macedonian UMCN)
using System;
using System.IO;
using System.Linq;
namespace Umcnmk
{
/// <summary>
/// Represents a Unique Master Citizen Number class(Macedonian UMCN)
/// Read more: https://www.uvmk.gov.mk/files/zakoni/Maticen_broj_na_graganinot_92.pdf
/// </summary>
~
~
~
@sweko
sweko / multipleImplementations.cs
Created April 10, 2019 09:06
Can Java do this?
interface IGeneric<T>
{
T GetValue(T param);
}
class Implementation: IGeneric<string>, IGeneric<int>
{
public string GetValue(string input) {
return "Bane "+input;
}
render() {
return <FancyInputBox {...placeholderObject}>
</FancyInputBox>;
}
const { placeholder } = this.props;
const placeholderObject = placeholder ? {placeholder} : {};
render() {
return <FancyInputBox placeholder={"Enter first name"}>
</FancyInputBox>;
}
render() {
return <FancyInputBox></FancyInputBox>;
}
@sweko
sweko / syncForEach.ts
Created October 24, 2017 18:26
Synchronous version of for each for use with async / await
interface Array<T> {
syncForEach(action: (value: T, index: number, array: T[]) => Promise<void>): void;
}
if (!Array.prototype.syncForEach) {
Array.prototype.syncForEach = async function<T> (action: (value: T, index: number, array: T[]) => Promise<void>): Promise<void> {
if (this == null) {
throw new TypeError('Array.prototype.syncForEach called on null or undefined');
}
string Solution(int[] source){
var sum = source.Sum();
if (sum % 3 != 0)
return "Impossible";
sum /= 3;
var opts = Enumerable.Range(0, 1 << source.Length)
.Select(i => source.Where((s, x) => ((1 << x) & i)!=0))
.Where(o => o.Sum()==sum)
.ToList();