Skip to content

Instantly share code, notes, and snippets.

View manivelarjunan's full-sized avatar

manivelarjunan

View GitHub Profile
// Input [10, 15, 3, 7], Target : 17
// if yes then return true else false.
// Brute force way.
//Solution 1:
function sumOfTwoNum(arr,target){
for(let i = 0 ; i < arr.length; i ++){
for(let j = 0; j < arr.length; j++){
function sumOfTwoNum(array,target){
let storeMap = {};
for(let arr of array){
if(storeMap[arr]){
return true;
}
storeMap[target - arr] = arr;
}
@manivelarjunan
manivelarjunan / app.component.spec.ts
Last active November 25, 2018 04:19
setup function in spec file.
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('App component', () => {
beforeEach(async(() => {
// The TestBed is the most important of the Angular testing utilities.
// The TestBed creates a dynamically-constructed Angular test module that emulates an Angular @NgModule.
// The TestBed.configureTestingModule() method takes a metadata object that can have most of the properties of an @NgModule.
TestBed.configureTestingModule({
declarations: [AppComponent]
@manivelarjunan
manivelarjunan / app.component.spec.ts
Last active December 2, 2018 22:24
App component spec file with beforeEach implementaion
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { UserComponent } from './user/user.component';
import { UserAsyncComponent } from './user-async/user-async.component';
describe('App component', () => {
beforeEach(async(() => {
// The TestBed is the most important of the Angular testing utilities.
// The TestBed creates a dynamically-constructed Angular test module that emulates an Angular @NgModule.
<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">
<h1>
Welcome to {{ title }}!
</h1>
<app-user></app-user>
<br>
<app-user-async></app-user-async>
</div>
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'Angular7-unit-testing!';
@manivelarjunan
manivelarjunan / app.component1.spec.ts
Created December 2, 2018 22:32
app.component.spec.ts with beforeEach implementaion
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { UserComponent } from './user/user.component';
import { UserAsyncComponent } from './user-async/user-async.component';
describe('App component', () => {
beforeEach(async(() => {
// The TestBed is the most important of the Angular testing utilities.
// The TestBed creates a dynamically-constructed Angular test module that emulates an Angular @NgModule.
// The TestBed.configureTestingModule() method takes a metadata object that can have most of the properties of an @NgModule.
<div *ngIf="isUserLoggedIn">
<p>
Welcome {{user.name}}
</p>
</div>
<div *ngIf="!isUserLoggedIn">
<p>
user is NOT logged In.
</p>
</div>
import { Component, OnInit } from '@angular/core';
import { UserService } from './user.service';
@Component({
selector: 'app-user',
templateUrl: './user.component.html',
styleUrls: ['./user.component.scss'],
providers: [UserService]
})
export class UserComponent implements OnInit {
import { Injectable } from '@angular/core';
@Injectable()
export class UserService {
user = {
name: 'Mannie'
};
getUser() {
return this.user;