Firstly install Brew on your MAC
- ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then install PHP
- brew update
- brew tap homebrew/dupes
- brew tap homebrew/php
- brew install php56
// Write a compression and decompression algorithm that results in a smalller string | |
// You can assume all the input parameters are letters of the alphabet | |
function isNumber(char) { | |
return !Number.isNaN(parseInt(char)) && typeof parseInt(char) === 'number' | |
} | |
// str is in this format, number then letter => "2a4f7s154v..." | |
function decompress(str) { | |
if (!str) return str |
// Installed npm packages: jquery underscore request express | |
// jade shelljs passport http sys lodash async mocha chai sinon | |
// sinon-chai moment connect validator restify ejs ws co when | |
// helmet wrench brain mustache should backbone forever debug jsdom | |
/* | |
Please write a function to score a game of bowling, | |
special scoring considerations | |
====================================== |
/* | |
Given a 2D array A[][2] of size N (1 ≤ N ≤ 103), where A[i][0] and A[i][1] denotes the length and breadth of rectangle i respectively. | |
Two rectangle i and j where (i < j) are similar if the ratio of their length and breadth is equal | |
A[i][0] / A[i][1] = A[j][0] / A[j][1] | |
Input : A[][2] = {{4, 8}, {15, 30}, {3, 6}, {10, 20}} | |
Output: 6 |
/* | |
There is a colony of 8 cells arranged in a straight line where each day every cell competes with its adjacent cells(neighbour). Each day, for each cell, if its neighbours are both active or both inactive, the cell becomes inactive the next day,. otherwise itbecomes active the next day. | |
Assumptions: The two cells on the ends have single adjacent cell, so the other adjacent cell can be assumsed to be always inactive. Even after updating the cell state. consider its pervious state for updating the state of other cells. Update the cell informationof allcells simultaneously. | |
Write a fuction cellCompete which takes takes one 8 element array of integers cells representing the current state of 8 cells and one integer days representing te number of days to simulate. An integer value of 1 represents an active cell and value of 0 represents an inactive cell. | |
*/ | |
function changeState(states) { | |
let temp = [] | |
const len = states.length | |
const virtualCell = 0 | |
for (var i = 0; i < len; i++) { |
/* | |
Problem, find the highest power less than a number n | |
Iterative solution: O(n) | |
Logarithmic solution: O(logn) | |
Bitwise solution: O(logn) | |
*/ | |
var highestPower = function(n, x) { | |
var res = 0; | |
for (var i = n; i >= 1; i--){ | |
var pow = Math.pow(x, i); |
/* | |
Problem: Given an array of objects parse those objects | |
to form meaningful key value pairs | |
*/ | |
// Input | |
const dataSource = [ | |
{id: 48, code: "firstName", description: "John"}, | |
{id: 49, code: "lastName", description: "Smith"}, | |
{id: 49, code: "occupation", description: "Agent"}, |
# Whenever i start coding i like to start with this command to clean up the repo and find out where we are | |
$ git fetch --prune origin && git status | |
# Merging is usually a good strategy as it allows for better tracking and dividing up the work | |
# Github offers a squash && merge option now on the PRs, but lets consider this: | |
# You want to test the feature branch locally before merging it and if there are any conflicts you want to resolve and test | |
$ git checkout master | |
$ git merge --squash feature_branch | |
$ git reset origin/master (Optional if we want to unstage all files that differ from origin master) | |
$ git add --all |
/* | |
* | |
* @function constructObject | |
* @param {file} file in dot notation ('a.b.c':'Hey', 'd.e.g': 'you') | |
* @return {Object} - a nested object. | |
* @example | |
* const object = constructObject(file) | |
* Returns the following: | |
* a: { | |
* b: { |
/* | |
* | |
* Flattens an object given a nested object structure | |
* @function flattenObject | |
* @param {Object} obj - The object whose values and keys you want to map over. | |
* @return {String} - A json string with key-value pairs. | |
* @example | |
* const original = { | |
* address: { | |
* 'addressLine1': 'Address (Line 1)', |
Firstly install Brew on your MAC
Then install PHP