Skip to content

Instantly share code, notes, and snippets.

View lffg's full-sized avatar

Luiz Felipe Gonçalves lffg

View GitHub Profile
function* enumerate(iterable) {
let i = 0;
for (const item of iterable) {
yield [i++, item];
}
}
function* withIsLast(iterable) {
const iterator = iterable[Symbol.iterator]();
let curr = iterator.next();
let source: &str = todo!("get some string slice here");
// A função `strip_prefix` retorna `Some` contendo o resto da string sem o prefixo se ele existir.
// Se não tiver o prefixo, retorna `None` (análogo ao `false` da outra função).
// Ver: https://doc.rust-lang.org/std/primitive.slice.html#method.strip_prefix
if let Some(tail) = source.strip_prefix(':') {
let cmd: Vec<_> = tail // Agora não preciso mais utilizar um range para remover o prefixo.
.split_ascii_whitespace()
.filter(|s| !s.is_empty())
.collect();
const data = [
{ id: 1, name: 'Foo-Dup' },
{ id: 1, name: 'Foo' },
{ id: 2, name: 'Bar' },
{ id: 3, name: 'Baz-Dup' },
{ id: 3, name: 'Baz' }
];
function dedupByKey(key, arr) {
const map = new Map();
@lffg
lffg / group-by.js
Last active November 26, 2021 19:49
const data = [
{ key: 'a', val: 'foo' },
{ key: 'b', val: 'bar' },
{ key: 'c', val: 'baz' },
{ key: 'a', val: 'qux' },
{ key: 'b', val: 'quxx' }
];
function groupBy(key, arr) {
const result = {};
function* gen() {
yield 1;
yield 2;
return 3;
}
function* withReturned(iterable) {
const iterator = iterable[Symbol.iterator]();
let curr;
while (

Keybase proof

I hereby claim:

  • I am lffg on github.
  • I am lffg (https://keybase.io/lffg) on keybase.
  • I have a public key ASAhDDaXO6SvSmVPSiTWGq6QEfVCJdF0aohodDHD1tLtPAo

To claim this, I am signing this object: