Skip to content

Instantly share code, notes, and snippets.

@johndavedecano
johndavedecano / cyclic_rotation.js
Created October 1, 2017 07:56
EXAMS - Cyclic Rotation
function solution(A, K) {
// write your code in JavaScript (Node.js 6.4.0)
var TMP = A;
for (var i=0; i<K; i++) {
var PART = TMP.slice(1, -1);
var FIRST = TMP.slice(0, 1);
var LAST = TMP.slice(-1);
@johndavedecano
johndavedecano / tape_equilibrium.js
Created October 1, 2017 08:00
EXAMS - Tape Equilibrium
function solution(A) {
var p, idx;
var leftSum = 0, rightSum = 0;
var totalSum = 0;
var lastMin, currentMin;
var N = A.length;
if (N == 2) { return Math.abs(A[0] - A[1]); }
if (N == 1) { return Math.abs(A[0]); }
@johndavedecano
johndavedecano / binary_gap_2.js
Last active October 1, 2017 18:03
EXAMS - Binary Gap
function solution(N) {
// write your code in JavaScript (Node.js 6.4.0)
var str = (N >>> 0).toString(2).split('');
var items = [];
var flag = false;
for (var i=0; i<str.length; i++) {
if (str[i] !== "0") {
flag = false;
@johndavedecano
johndavedecano / distinct_values.js
Created October 1, 2017 18:09
EXAMS - DISTINCT VALUES
// you can write to stdout for debugging purposes, e.g.
// console.log('this is a debug message');
function solution(A) {
// write your code in JavaScript (Node.js 6.4.0)
return A.filter((x, y, z) => z.indexOf(x) === y).length;
}
@johndavedecano
johndavedecano / odd_occurences.js
Created October 1, 2017 19:36
EXAMS - ODD OCCURENCES
function solution(A) {
// write your code in JavaScript (Node.js 4.0.0)
var B = [];
for(var i = 0; i < A.length; i++){
var index = B.indexOf(A[i]);
if(index > -1) B.splice(index, 1);
else B.push(A[i]);
}
return B[0];
}
@johndavedecano
johndavedecano / asterisk_pyramid.js
Created December 11, 2017 09:33
EXAMS - Asterisk Pyramid
function solution(height) {
var tree = [];
for (var i=0; i<5; i++) {
var child = "*";
for(var s=0; s<i; s++) {
child = child + "*"
}
tree[i] = child;
}
@johndavedecano
johndavedecano / mention.jsx
Created January 11, 2018 14:57
mention.jsx
import React, { Component } from 'react';
import Popper from 'popper.js';
class RangeRef {
rect = {};
constructor(rect) {
if (rect) {
this.rect = rect;
}
@johndavedecano
johndavedecano / largest_consecutive_product.js
Created January 26, 2018 08:53
To Find Largest Consecutive Product Of Numbers In 1D Array
export function solution(given) {
var highest = [0, 0, 0];
for (var i=0; i<given.length; i++) {
var prev = given[i];
var next = !given[i + 1] ? 0 : given[i + 1];
var total = prev * next;
if (total > highest[2]) {
highest = [prev, next, prev * next];
}
}
@johndavedecano
johndavedecano / jenkins-basics.txt
Created September 3, 2018 12:05
Jenkins Basics - Multibranch
1. Create groovy jenkins file
2. Setup credentials for docker hub and github
3. Create new job
4. Select Multibranch Pipeline
5. Select Branch Source
6. Select Repository
7. Select Jenkins File
@johndavedecano
johndavedecano / laravel.xml
Created October 8, 2018 11:53
Laravel Coding Standard for PHP Storm
<code_scheme name="Laravel">
<option name="OTHER_INDENT_OPTIONS">
<value>
<option name="INDENT_SIZE" value="4" />
<option name="CONTINUATION_INDENT_SIZE" value="8" />
<option name="TAB_SIZE" value="4" />
<option name="USE_TAB_CHARACTER" value="true" />
<option name="SMART_TABS" value="false" />
<option name="LABEL_INDENT_SIZE" value="0" />
<option name="LABEL_INDENT_ABSOLUTE" value="false" />