Skip to content

Instantly share code, notes, and snippets.

View NyaGarcia's full-sized avatar
🐈

Nya NyaGarcia

🐈
View GitHub Profile
@NyaGarcia
NyaGarcia / filter-falsy.pipe.ts
Created April 27, 2021 22:04
Adding transform types to the FilterFalsyPipe
@Pipe({ name: "filterFalsy" })
export class FilterFalsyPipe implements PipeTransform {
transform<T>(array: T[]): T[] {}
}
@NyaGarcia
NyaGarcia / filter-falsy.pipe.ts
Created April 27, 2021 22:02
Implementing PipeTransform in the FilterFalsyPipe
@Pipe({ name: "filterFalsy" })
export class FilterFalsyPipe implements PipeTransform {
transform() {}
}
@NyaGarcia
NyaGarcia / filter-falsy.pipe.ts
Created April 27, 2021 22:00
Adding the Pipe decorator to the FilterFalsyPipe
@Pipe({ name: "filterFalsy" })
export class FilterFalsyPipe {}
@NyaGarcia
NyaGarcia / filter-falsy.pipe.ts
Created April 27, 2021 21:51
The filterFalsy pipe
@Pipe({ name: "filterFalsy" })
export class FilterFalsyPipe implements PipeTransform {
transform<T>(array: T[]): T[] {
return array.filter(Boolean);
}
}
@NyaGarcia
NyaGarcia / app.component.html
Created April 27, 2021 21:44
Using the filterFalsy pipe
<h1>The Awesome filterFalsy Pipe in Action</h1>
{{falsyArray | filterFalsy}}
@NyaGarcia
NyaGarcia / app.module.ts
Created April 27, 2021 21:42
Adding the FilterFalsyPipe to the AppModule declarations
@NgModule({
imports: [BrowserModule, FormsModule],
declarations: [AppComponent, FilterFalsyPipe],
bootstrap: [AppComponent]
})
export class AppModule {}
@NyaGarcia
NyaGarcia / app.component.ts
Created April 27, 2021 21:32
Creating an array with falsy values in the app.component
import { Component } from "@angular/core";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
falsyArray = [false, "No", 0, "more", undefined, "falsy", null, "values", NaN];
}
@NyaGarcia
NyaGarcia / arrow-function-arguments.js
Created March 9, 2021 20:01
arguments object in an arrow function
const getArguments = () => Array.from(arguments);
console.log(getArguments(1, 2, 3, 4));
// Output: [ƒ (), Object, Object, "/~/index.js", "/~", Window, Window, Object, ƒ c()]
console.log(getArguments("arguments", "is", "cool"));
// Output: [ƒ (), Object, Object, "/~/index.js", "/~", Window, Window, Object, ƒ c()]
@NyaGarcia
NyaGarcia / traditional-function-arguments.js
Last active March 9, 2021 20:00
Showing arguments object in a traditional function
function getArguments() {
return Array.from(arguments);
}
console.log(getArguments(1, 2, 3, 4));
// Output: [1, 2, 3, 4]
console.log(getArguments("arguments", "is", "cool"));
// Output: ["arguments", "is", "cool"]
@NyaGarcia
NyaGarcia / rest-parameters-arrow.js
Created March 9, 2021 19:09
Rest parameters in arrow function
const add = (...args) => args.reduce((prev, curr) => prev + curr);
console.log(add(1, 2, 3, 4, 5, 6));
// Output: 21