Skip to content

Instantly share code, notes, and snippets.

@marcuszierke
marcuszierke / tailRecursion.js
Last active October 25, 2021 21:33
Tail Recursion - Collartz
const simpleFac = (n) => {
if (n === 1) return n
return n * simpleFac(n - 1)
}
const TRFac = (n, a) => {
if (n === 0) return a
return TRFac(n - 1, a * n)
}
// hier wird der Stack 5 mal gecallt => was Sinn macht
@marcuszierke
marcuszierke / index.js
Created March 24, 2020 16:32
Summarizer
summarizer = (sum) => {
if (sum === 0) {
return 0;
}
return sum + summarizer(sum - 1);
}
console.log(summarizer(100));
@marcuszierke
marcuszierke / index.js
Last active March 24, 2020 16:27
MagicNumber
const magicNumber = (range) => {
[...Array(range + 1).keys()].map(n => {
const res = n**5 - 5*n**3 + 4*n;
if (res >= 120 && (res % 120 !== 0)) {
return n;
}
})
return 'no number found';
}
@marcuszierke
marcuszierke / contactForm.js
Created October 16, 2019 10:21
React Contact Form without using state
import React, { useState } from 'react';
const ContactForm = () => {
const [newsletterValue, setNewsletterValue] = useState(false);
function changeNewsletterValue() {
setNewsletterValue(!newsletterValue);
}
function handleSubmit(event) {
@marcuszierke
marcuszierke / contactForm2.js
Last active October 16, 2019 10:18
React Contact Form without using state
import React, { useState } from 'react';
const ContactForm = () => {
const [newsletterValue, setNewsletterValue] = useState(false);
function changeNewsletterValue() {
setNewsletterValue(!newsletterValue);
}
...
@marcuszierke
marcuszierke / contactForm1.js
Created October 16, 2019 09:58
React Contact Form without using state
import React from 'react';
const ContactForm = () => {
function handleSubmit(event) {
event.preventDefault();
const data = {};
const formElements = Array.from(event.target);
formElements.map(input => (data[input.name] = input.value));
}
import unittest
def bn(draws=None, balls=None):
#error message for missing input
if draws == None or balls == None: return "Missing Input"
#error message for negative input
if draws < 0 or balls < 0: return "Input has to be a number >= 0"
#error message if draws > balls
if balls<draws: return "Input number for draws has to be <= input number for balls"
#defining the factorial function
@marcuszierke
marcuszierke / ticTacToe.html
Created October 31, 2017 18:03
Another Free Code Camp challenge to code the Tic Tac Toe game
<html>
<head>
<meta charset="utf-8">
<title>Free Code Camp - Tic Tac Toe Game</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.12/themes/redmond/jquery-ui.css">
<style type="text/css"><
body {
background-color: white;
@marcuszierke
marcuszierke / simonGame.html
Created October 29, 2017 21:08
FCC Simon Game
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FCC Simon Game</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<style type="text/css">
body {
background-color: beige;
@marcuszierke
marcuszierke / twitchTV.html
Last active October 19, 2017 17:46
Free Code Camp - TwitchTV
<html>
<head>
<meta charset="utf-8">
<title>Twitch.tv - Viewer</title>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style type="text/css">
<link href="https://fonts.googleapis.com/css?family=Catamaran" rel="stylesheet">