mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-11 05:13:02 -05:00
feat(challenge): add a pipe challenge serie
This commit is contained in:
36
apps/pipe-hard/src/app/app.component.ts
Normal file
36
apps/pipe-hard/src/app/app.component.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { NgFor } from '@angular/common';
|
||||
import { Component } from '@angular/core';
|
||||
import { PersonUtils } from './person.utils';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [NgFor],
|
||||
selector: 'app-root',
|
||||
template: `
|
||||
<div *ngFor="let activity of activities">
|
||||
{{ activity.name }} :
|
||||
<div
|
||||
*ngFor="let person of persons; let index = index; let isFirst = first">
|
||||
{{ showName(person.name, index) }}
|
||||
{{ isAllowed(person.age, isFirst, activity.minimumAge) }}
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
})
|
||||
export class AppComponent {
|
||||
persons = [
|
||||
{ name: 'Toto', age: 10 },
|
||||
{ name: 'Jack', age: 15 },
|
||||
{ name: 'John', age: 30 },
|
||||
];
|
||||
|
||||
activities = [
|
||||
{ name: 'biking', minimumAge: 12 },
|
||||
{ name: 'hiking', minimumAge: 25 },
|
||||
{ name: 'dancing', minimumAge: 1 },
|
||||
];
|
||||
|
||||
showName = PersonUtils.showName;
|
||||
|
||||
isAllowed = PersonUtils.isAllowed;
|
||||
}
|
||||
17
apps/pipe-hard/src/app/person.utils.ts
Normal file
17
apps/pipe-hard/src/app/person.utils.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
const showName = (name: string, index: number) => {
|
||||
// very heavy computation
|
||||
return `${name} - ${index}`;
|
||||
};
|
||||
|
||||
const isAllowed = (age: number, isFirst: boolean, activityAge: number) => {
|
||||
if (isFirst) {
|
||||
return 'always allowed';
|
||||
} else {
|
||||
return age > activityAge ? 'allowed' : 'declined';
|
||||
}
|
||||
};
|
||||
|
||||
export const PersonUtils = {
|
||||
showName,
|
||||
isAllowed,
|
||||
};
|
||||
0
apps/pipe-hard/src/assets/.gitkeep
Normal file
0
apps/pipe-hard/src/assets/.gitkeep
Normal file
3
apps/pipe-hard/src/environments/environment.prod.ts
Normal file
3
apps/pipe-hard/src/environments/environment.prod.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export const environment = {
|
||||
production: true,
|
||||
};
|
||||
16
apps/pipe-hard/src/environments/environment.ts
Normal file
16
apps/pipe-hard/src/environments/environment.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// This file can be replaced during build by using the `fileReplacements` array.
|
||||
// `ng build` replaces `environment.ts` with `environment.prod.ts`.
|
||||
// The list of file replacements can be found in `angular.json`.
|
||||
|
||||
export const environment = {
|
||||
production: false,
|
||||
};
|
||||
|
||||
/*
|
||||
* For easier debugging in development mode, you can import the following file
|
||||
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
|
||||
*
|
||||
* This import should be commented out in production mode because it will have a negative impact
|
||||
* on performance if an error is thrown.
|
||||
*/
|
||||
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
|
||||
BIN
apps/pipe-hard/src/favicon.ico
Normal file
BIN
apps/pipe-hard/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
13
apps/pipe-hard/src/index.html
Normal file
13
apps/pipe-hard/src/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>PipeHard</title>
|
||||
<base href="/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
10
apps/pipe-hard/src/main.ts
Normal file
10
apps/pipe-hard/src/main.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { enableProdMode } from '@angular/core';
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app/app.component';
|
||||
import { environment } from './environments/environment';
|
||||
|
||||
if (environment.production) {
|
||||
enableProdMode();
|
||||
}
|
||||
|
||||
bootstrapApplication(AppComponent).catch((err) => console.error(err));
|
||||
52
apps/pipe-hard/src/polyfills.ts
Normal file
52
apps/pipe-hard/src/polyfills.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* This file includes polyfills needed by Angular and is loaded before the app.
|
||||
* You can add your own extra polyfills to this file.
|
||||
*
|
||||
* This file is divided into 2 sections:
|
||||
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
|
||||
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
|
||||
* file.
|
||||
*
|
||||
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
|
||||
* automatically update themselves. This includes recent versions of Safari, Chrome (including
|
||||
* Opera), Edge on the desktop, and iOS and Chrome on mobile.
|
||||
*
|
||||
* Learn more in https://angular.io/guide/browser-support
|
||||
*/
|
||||
|
||||
/***************************************************************************************************
|
||||
* BROWSER POLYFILLS
|
||||
*/
|
||||
|
||||
/**
|
||||
* By default, zone.js will patch all possible macroTask and DomEvents
|
||||
* user can disable parts of macroTask/DomEvents patch by setting following flags
|
||||
* because those flags need to be set before `zone.js` being loaded, and webpack
|
||||
* will put import in the top of bundle, so user need to create a separate file
|
||||
* in this directory (for example: zone-flags.ts), and put the following flags
|
||||
* into that file, and then add the following code before importing zone.js.
|
||||
* import './zone-flags';
|
||||
*
|
||||
* The flags allowed in zone-flags.ts are listed here.
|
||||
*
|
||||
* The following flags will work for all browsers.
|
||||
*
|
||||
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
|
||||
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
|
||||
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
|
||||
*
|
||||
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
|
||||
* with the following flag, it will bypass `zone.js` patch for IE/Edge
|
||||
*
|
||||
* (window as any).__Zone_enable_cross_context_check = true;
|
||||
*
|
||||
*/
|
||||
|
||||
/***************************************************************************************************
|
||||
* Zone JS is required by default for Angular itself.
|
||||
*/
|
||||
import 'zone.js'; // Included with Angular CLI.
|
||||
|
||||
/***************************************************************************************************
|
||||
* APPLICATION IMPORTS
|
||||
*/
|
||||
1
apps/pipe-hard/src/styles.scss
Normal file
1
apps/pipe-hard/src/styles.scss
Normal file
@@ -0,0 +1 @@
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
Reference in New Issue
Block a user