Skip to content

Instantly share code, notes, and snippets.

@Muzietto
Muzietto / Instructions.md
Created November 29, 2017 11:44
Instructions

Open this readme in your browser


Instructions

  • Use the given minimal app project to implement the User Stories
  • Take your time. This coding challenge is not designed to get finished
  • Focus on functionality, but do not neglect appearance
  • Try to write generic and re-usable code
  • You are free to implement the application logic any way you like, using any library you think is suited for the task. However, we expect you to be able to justify with solid motives every choice you make (and please be advised that we LOVE vanilla JS)
@Muzietto
Muzietto / CmsEntry.json
Last active June 30, 2017 10:10
Generic item for headless CMS
{
"id": "http://socialsweethearts.de/CmsEntry#",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "schema for an headless_cms_mvp entry",
"type": "object",
"properties": {
"value": {
"type": "object",
"oneOf": [{
"$ref": "#/definitions/ListicleItems",
@Muzietto
Muzietto / index.js
Created March 16, 2017 08:43
npm configuration and app entry script for media library using redux-saga (https://scotch.io/tutorials/build-a-media-library-with-react-redux-and-redux-saga-part-1)
import React from 'react';
import ReactDOM from 'react-dom';
import {Router, hashHistory} from 'react-router';
import routes from './routes';
// require the routes and render to the DOM using ReactDOM API
ReactDOM.render(
<Router history={hashHistory} routes={routes} />,
document.getElementById('root')
)
@Muzietto
Muzietto / promiseWriteCsvFile.js
Last active March 8, 2017 04:20
Promise to write data into a CSV file using npm module 'csv-write-stream'
putPortfolioData = function(result, dataSinkName) {
return new Promise(function (resolve, reject) {
var filename = __dirname + dataSinkName,
writer = csvStream(),
ws = fs.createWriteStream(filename)
;
writer.on('error', function(error) {
reject(error);
});
@Muzietto
Muzietto / StackBasedLeader.js
Last active January 10, 2017 08:51
Finding a vector leader faking the usage of a stack
function stackBasedLeader(A) {
var n = A.length;
var occurrences = {};
var stackSize = 0;
var stackElem = -1;
for (let a of A) {
if (!occurrences[a]) occurrences[a] = 0;
occurrences[a]++;
@Muzietto
Muzietto / AllPrimeFactorsOfN.js
Created January 8, 2017 13:43
Eratosthenes to the rescue in finding prime factors of a given number
function primeFactorsOf(n) {
var lpfs = leastPrimeFactorsOf(n);
return helper(lpfs, n, []);
function helper(lpfs, n, arra) {
if (lpfs[n] == 0) return arra.concat([n]);
return helper(lpfs, n/lpfs[n], arra.concat([lpfs[n]]));
}
}
function leastPrimeFactorsOf(n) {
@Muzietto
Muzietto / GenomicRangeQuery.js
Last active January 8, 2017 10:24
Kinda SumPrefix solution using differences to express distances from relevant targets
function genomicRangeQuery(nucleotides, mins, maxs) {
var result = new Array(mins.length).fill(-1);
var distances = distancesFromLastSeen(nucleotides);
for (var i = 0; i < mins.length; i++) {
var segmentWidth = maxs[i] - mins[i] + 1;
if (distances['A'][maxs[i]] < segmentWidth) {
result[i] = 1;
continue;
}
if (distances['C'][maxs[i]] < segmentWidth) {
@Muzietto
Muzietto / NumberSolitaire.js
Last active January 5, 2017 17:27
Dynamic programming - Playing all possible solitaires on a board, throwing one die, up to the last square.
function numberSolitaire(arra) {
var dp = new Array(arra.length).fill(0);
dp[0] = arra[0];
for (var i = 1; i < arra.length; i++) {
var max = -Infinity;
for (var j = 1; j <= 6; j++) {
if (i - j < 0) break;
max = Math.max(max, dp[i-j] + arra[i]);
}
dp[i] = max;
@Muzietto
Muzietto / KnapsackContents.js
Created January 4, 2017 16:56
Knapsack 0/1 - reverse function that deducts the knapsack content starting from its total value.
function knapsackContents(items, maxWeight) {
items = items.sort((a,b)=>a.weight-b.weight);
var knapsacks = knapsack01(maxWeight, items, true);
var result = [];
return contentsHelper(knapsacks, items);
function contentsHelper(matrix, items) {
var column = matrix[matrix.length-1]
var numItems = items.length;
if (numItems === 0) return [];
@Muzietto
Muzietto / LogicalKnapsack01
Last active January 4, 2017 17:04
A knapsack 0/1 algo that cycles first and foremost through the knapsack weights - clumsier but more logical
function knapsack01(maxWeight, items, returnAllKnapsacks) {
items = items.sort((a,b)=>a.weight-b.weight);
var knapsacks = new Array(maxWeight + 1);
for (var i = 0; i <= maxWeight; i++) {
knapsacks[i] = new Array(items.length);
for (var j = 0; j < items.length; j++) {
knapsacks[i][j] = 0;
};
};