Skip to content

Instantly share code, notes, and snippets.

View hackingbeauty's full-sized avatar
🎯
Focusing

Mark Joseph (Muskardin) hackingbeauty

🎯
Focusing
View GitHub Profile
@hackingbeauty
hackingbeauty / gist:6586395
Created September 16, 2013 20:47
Get the count of all subsets in array [1,2,3,4,6], that when summed, equal any element in the array. Input: [1,2,3,4,6] Output: 4 (The subsets are: [ 1, 2 ], [ 1, 3 ], [ 2, 4 ], [ 1, 2, 3 ] )
function findSubsets(arr){
var subsets = [],
permutations = getPermutations(arr,2);
console.log(findInArr(arr, permutations));
return findInArr(arr, permutations).length;
}
function findInArr(arr, permutations){
var returnArr = [], sum;
for(var i = 0; i<permutations.length; i++){ // iterate through each permutation
function merge(obj1, obj2){
var mergedObj = {}, subHash = {};
for(key in obj1){
mergedObj[key] = obj1[key];
}
for(key in obj2){ // iterate through level1 keys of obj2
if(!mergedObj.hasOwnProperty(key)){
mergedObj[key] = obj2[key]; // if key of obj2 does not exist, add to mergedObj
} else {
subHash = mergedObj[key];
@hackingbeauty
hackingbeauty / gist:6986054
Created October 15, 2013 03:23
Interview question: dynamically create N input nodes with +- in between inputs. Evaluate expression. Numbers allowed only.
<div id="container"></div>
<div id="result"></div>
<input type="submit" id="submit-button" />
<script>
VIKI = {
init: function(){
var inputs = this.createNodes(5);
this.computeValue(inputs);
@hackingbeauty
hackingbeauty / gist:7711146
Created November 29, 2013 20:00
Write a function that takes in an array of integers, finds all numbers that are divisible by 3, and returns the second largest value .
function secondLargest(arr){
var newArr = [], secondLargest;
for(var i = 0; i < arr.length; i++){
if(arr[i] % 3 === 0){
newArr.push(arr[i]);
}
}
newArr.sort(function(a,b){return a-b});
secondLargest = newArr[newArr.length - 1];
return secondLargest;
@hackingbeauty
hackingbeauty / gist:7763288
Created December 3, 2013 03:08
Package.json
{
"name": "chat-salon",
"version": "0.0.1-18",
"private": true,
"scripts": {
"test": "./bin/test",
"start": "node app.js"
},
"dependencies": {
"express": "3.4.0",
@hackingbeauty
hackingbeauty / gist:e34efaf53e7ccec60455
Created October 13, 2014 20:24
Ways of creating objects
// Object literal pattern aka Singleton
var Animal = {
speak: function(words){
console.log(words)
}
}
// Module Pattern
var Animal = (function(){
var internalVar = 1;
@hackingbeauty
hackingbeauty / interview test
Created March 3, 2015 22:34
Interview test I had
'use strict';
function Calculator(){
}
Calculator.prototype.add = function( int1, int2 ){
return int1 + int2;
};
function findMin( A, K ){
var newArr = [];
for(var i = 0; i< A.length; i++){
if(A[i-K+1] < A[i]){
newArr.push( A[i-K+1] );
} else {
newArr.push( A[i] );
}
import React from 'react';
import Router from 'react-router';
import BrowserHistory from 'react-router/lib/History';
import App from './components/App.jsx';
import TaskList from './components/TaskList.jsx';
import { DefaultRoute, Link, Route, RouteHandler } from 'react-router';
var routes = (
<Route handler={App} path="/">
<DefaultRoute handler={App} />
// 22: class - creation
// To do: make all tests pass, leave the assert lines unchanged!
describe('class creation', () => {
it('is as simple as `class XXX {}`', function() {
class TestClass {};
const instance = new TestClass();
assert.equal(typeof instance, 'object');