This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Given an array, assign the multiplication of all values except current for each position (in-place) | |
| function getMul(arr) { | |
| let res = arr.reduce((prev, curr, index, array) => prev * curr, 1); | |
| arr.map(v => console.log(res/v)); | |
| } | |
| let arr = [1, 2, 3, 4, 5, 6]; | |
| getMul(arr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Merge sort | |
| function mergeSort(vals, scrtach, start, end) { | |
| if (start == end) return; | |
| let mid = Math.floor((start + end) / 2); | |
| mergeSort(vals, scratch, start, mid); | |
| mergeSort(vals, scratch, mid + 1, end); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Find all possible sums made from subsets of items from array A | |
| function subsetSums(arr, l, r, sum = 0) { | |
| // Print current subset | |
| if (l > r) { | |
| console.log(sum); | |
| return; | |
| } | |
| // Subset including arr[l] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Count inversions of array | |
| function getInvCount(arr) { | |
| let n = arr.length; | |
| let invCount = 0; | |
| for (let i = 0; i < n - 1; i++) | |
| for (let j = i + 1; j < n; j++) | |
| if (arr[i] > arr[j]) | |
| invCount++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Given an array of n integers, find and print the minimum absolute difference | |
| // between any two elements in the array (where i!=j, 2<=n<=10^9) | |
| function findMinDiff(arr) { | |
| let n = arr.length; | |
| // Sort array in non-decreasing order | |
| arr.sort(function(a, b) { | |
| return a - b; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Implement Queue interface using Stack interface as a storage | |
| function queue() { | |
| this.stack = []; | |
| } | |
| queue.prototype.enq = function(item) { | |
| this.stack.push(item); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Restore bracket sequence | |
| function restore(str) { | |
| let arr = []; | |
| let counter = 0; | |
| for(let i=0; i<str.length; i++) { | |
| if (str[i]=='(') { | |
| arr.push('('); | |
| counter++; | |
| } else { // str[i]==')' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const tree = { | |
| and: { | |
| left: { | |
| and: { | |
| left: { | |
| le: { | |
| left: { | |
| fieldRef: "a.count" | |
| }, | |
| right: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <input | |
| #inputElement | |
| [value]="value" | |
| [type]="type" | |
| [id]="id" | |
| [placeholder]="placeholder" | |
| (change)="onChange($event)" | |
| (keyup)="onKeyup($event)" | |
| (blur)="onBlur($event)"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component, Input, ViewChild, ElementRef } from '@angular/core'; | |
| @Component({ | |
| selector: 'custom-input', | |
| templateUrl: './input.component.html', | |
| styleUrls: ['./input.component.css'] | |
| }) | |
| export class InputComponent { | |
| value: string = ''; | |
| @Input() type: string = 'text'; |