Skip to content

Instantly share code, notes, and snippets.

View ppraksa's full-sized avatar
👋
code in dandy style

Pawel ppraksa

👋
code in dandy style
  • DandyCode
  • Poland
View GitHub Profile
var shape = {
type: "",
getType: function () {
return this.type;
},
};
function Triangle(a, b, c) {
this.type = "triangle";
this.a = a;
Array.prototype.shuffle = function () {
let c = [];
const MAX = this.length;
function testAndShuffle(item) {
let index = Math.floor(Math.random() * MAX);
if (typeof c[index] === "undefined") {
c[index] = item;
} else {
function getRgb(hex) {
try {
if (
typeof hex !== "string" ||
(hex.length !== 7 && hex.length !== 4) ||
hex[0] !== "#"
) {
throw {
name: "Problem",
message: "This is not a proper string",
function Person(name) {
console.log("old constructor");
let obj;
// Another time just return obj above
Person = function Person() {
console.log("new constructor");
return obj;
};
// Implementation of observable value with cb function
function dandycode() {
var value = Array.prototype.slice.call(arguments)[0];
var dandy = {};
if (!(this instanceof dandycode)) {
return new dandycode(value);
}
this.value = value;
class Person {
constructor(name) {
this.name = name;
}
count() {
return Person.prototype.counter++;
}
}
Person.prototype.counter = 0;
class Humanoid {
constructor(name) {
this.name = name;
}
say() {
console.log(this.name);
}
}
class Human extends Humanoid {
function Device(power) {
this.power = power;
this.turnPower = function() { this.power = !this.power };
}
Device.prototype.sayHello = function() { this.power ? console.log('hello, the power is on') : ''}
function Computer(proccessor, memory) {
this.proccessor = proccessor;
this.memory = memory;
const asyncReducerFactory = (name) => {
return (state = { data: null, isLoading: false, error: null }, action) => {
switch (action.type) {
case `FETCH_${name}_STARTED`:
return { data: null, isLoading: true, error: null };
case `FETCH_${name}_SUCCESS`:
return { data: action.payload, isLoading: false, error: null };
case `FETCH_${name}_ERROR`:
return { data: null, isLoading: false, error: action.payload };
default:
// jasmine
const customMatchers = {
toBeArray: function () {
return {
compare: function (item) {
const result = {
pass: item instanceof Array,
message: ''
};