Skip to content

Instantly share code, notes, and snippets.

View deadkff01's full-sized avatar
🪐

Dennis Kaffer deadkff01

🪐
View GitHub Profile
@deadkff01
deadkff01 / mapWithReduce.js
Last active June 4, 2018 18:06
JavaScript - Map function with reduce
const names = ['pikachu', 'squirtle', 'charmander']
const capitalize = function (name) {
const capitalizedFirst = name[0].toUpperCase()
const rest = name.slice(1)
return [capitalizedFirst].concat(rest).join('')
}
// map function with reduce
const map = (list, mapFunction) => {
@deadkff01
deadkff01 / thedescent.js
Created December 12, 2016 16:17
The Descent - Solution
// game loop
while (true) {
var largestMontain = 0;
var indexToShot = 0;
for (var i = 0; i < 8; i++) {
var mountainH = parseInt(readline()); // represents the height of one mountain.
if(largestMontain < mountainH) {
largestMontain = mountainH;
indexToShot = i;
@deadkff01
deadkff01 / divideWithLogarithms.js
Last active April 18, 2018 18:50
JavaScript divide function without using "/"
// Multiplication and division rules... ((+)*(+)=+) ((-)*(-)=+) ((+)*(-)=-) ((-)*(+)=-)
const multiply = (x, y) => {
let r = Math.exp(Math.log(Math.abs(x)) + Math.log(Math.abs(y))).toFixed(2)
return Number((x < 0 && y < 0) ? r : (x < 0 || y < 0) ? -r : r)
}
const divide = (x, y) => {
return (x === 0) ? 0 : multiply(((multiply(x, y) < 0) ? -1.0 : 1.0), Math.exp(Math.log(Math.abs(x)) - Math.log(Math.abs(y))))
}
@deadkff01
deadkff01 / TLC_1.js
Created October 16, 2016 06:56
The Last Crusade - Episode 1 Solution
var grid = [];
var inputs = readline().split(' ');
var W = parseInt(inputs[0]); // number of columns.
var H = parseInt(inputs[1]); // number of rows.
for (var i = 0; i < H; i++) {
var LINE = readline(); // represents a line in the grid and contains W integers. Each integer represents one room of a given type.
grid[i] = LINE.split(' ');
}
var EX = parseInt(readline()); // the coordinate along the X axis of the exit (not useful for this first mission, but must be read).
@deadkff01
deadkff01 / SEL.js
Created September 25, 2016 04:06
Stock Exchange Losses - Solution
var n = parseInt(readline());
var inputs = readline().split(' ');
var values = [];
for (var i = 0; i < n; i++) {
var v = parseInt(inputs[i]);
values.push(v);
}
@deadkff01
deadkff01 / app.js
Created June 15, 2016 17:52
Real-time example in Node.js
var express = require('express')
, app = express()
, sse = require('./sse')
var connections = []
, votes = {yes: 0, no: 0}
app.engine('jade', require('jade').__express)
app.set('view engine', 'jade')
@deadkff01
deadkff01 / dwarfs.js
Created February 25, 2016 21:23
Dwarfs standing on the shoulders of giants - Solution
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
var graph = [];
var n = parseInt(readline()); // the number of adjacency relations
for (var i = 0; i < n; i++) {
var inputs = readline().split(' ');
var xi = parseInt(inputs[0]); // the ID of a person which is adjacent to yi
@deadkff01
deadkff01 / teads.js
Created February 20, 2016 18:49
Teads Sponsored Contest - Solution
var graph = [];
var n = parseInt(readline()); // the number of adjacency relations
for (var i = 0; i < n; i++) {
var inputs = readline().split(' ');
var xi = parseInt(inputs[0]); // the ID of a person which is adjacent to yi
var yi = parseInt(inputs[1]); // the ID of a person which is adjacent to xi
if (!graph[xi]) {
graph[xi] = { data: xi, edges: [] };
}
graph[xi].edges.push(yi);
@deadkff01
deadkff01 / removeAccentsString.js
Created February 9, 2016 14:37
Solution to remove accents in the words.
makeSortString = (function() {
var translate_re = /[¹²³áàâãäåaaaÀÁÂÃÄÅAAAÆccç©CCÇÐÐèéê?ëeeeeeÈÊËÉ?EEEEE€gGiìíîïìiiiÌÍÎÏ?ÌIIIlLnnñNNÑòóôõöoooøÒÓÔÕÖOOOØŒr®Ršs?ߊS?ùúûüuuuuÙÚÛÜUUUUýÿÝŸžzzŽZZ]/g;
var translate = {
"¹":"1","²":"2","³":"3","á":"a","à":"a","â":"a","ã":"a","ä":"a","å":"a","a":"a","a":"a","a":"a","À":"a","Á":"a","Â":"a","Ã":"a","Ä":"a","Å":"a","A":"a","A":"a",
"A":"a","Æ":"a","c":"c","c":"c","ç":"c","©":"c","C":"c","C":"c","Ç":"c","Ð":"d","Ð":"d","è":"e","é":"e","ê":"e","?":"e","ë":"e","e":"e","e":"e","e":"e","e":"e",
"e":"e","È":"e","Ê":"e","Ë":"e","?":"e","E":"e","E":"e","E":"e","E":"e","E":"e","€":"e","g":"g","G":"g","i":"i","ì":"i","í":"i","î":"i","ï":"i","ì":"i","i":"i",
"i":"i","i":"i","Ì":"i","Í":"i","Î":"i","Ï":"i","?":"i","Ì":"i","I":"i","I":"i","I":"i","l":"l","L":"l","n":"n","n":"n","ñ":"n","N":"n","N":"n","Ñ":"n","ò":"o",
"ó":"o","ô":"o","õ":"o","ö":"o","o":"o","o":"o","o":"o","ø":"o","Ò":"o","Ó":"o","Ô":"o","Õ":"o","Ö":"o","O":"o","O":"o","O":"o","Ø":"o","Œ":"o","r":"r","®":"r",
"
@deadkff01
deadkff01 / AuthToken.js
Created February 9, 2016 14:26
AngularJS - FacebookAuth
app.factory('authToken',['$cookieStore', '$location', function($cookieStore, $location){
var token = {};
token.start = null;
token.setAccessToken = function(accessToken) {
$cookieStore.put('accessToken', accessToken);
}
token.getAccessToken = function() {
token.authToken = $cookieStore.get('accessToken');