This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Plant(name) { | |
this.name = name; | |
}; | |
Plant.prototype.height = 0; | |
Plant.prototype.grow = function() { | |
this.height += 1; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var diff = function (obj1, obj2) { | |
// Make sure an object to compare is provided | |
if (!obj2 || Object.prototype.toString.call(obj2) !== '[object Object]') { | |
return obj1; | |
} | |
// | |
// Variables | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var deepDiffMapper = function() { | |
return { | |
VALUE_CREATED: 'created', | |
VALUE_UPDATED: 'updated', | |
VALUE_DELETED: 'deleted', | |
VALUE_UNCHANGED: 'unchanged', | |
map: function(obj1, obj2) { | |
if (this.isFunction(obj1) || this.isFunction(obj2)) { | |
throw 'Invalid argument. Function given, object expected.'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentDidUpdate(prevProps, prevState) { | |
Object.entries(this.props).forEach(([key, val]) => | |
prevProps[key] !== val && console.log(`Prop '${key}' changed`) | |
); | |
Object.entries(this.state).forEach(([key, val]) => | |
prevState[key] !== val && console.log(`State '${key}' changed`) | |
); | |
} | |
// hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable global-require */ | |
const webpack = require('webpack'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const path = require('path'); | |
const ip = require('ip').address(); | |
const postcssImport = require('postcss-import'); | |
const precss = require('precss'); | |
const postcssClearfix = require('postcss-clearfix'); | |
const postcssCenter = require('postcss-center'); | |
const postcssMath = require('postcss-math'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable global-require */ | |
const path = require('path'); | |
const webpack = require('webpack'); | |
const TerserPlugin = require('terser-webpack-plugin'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const CompressionPlugin = require('compression-webpack-plugin'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const postcssImport = require('postcss-import'); | |
const precss = require('precss'); | |
const postcssClearfix = require('postcss-clearfix'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
export default function withPropsChecker(WrappedComponent) { | |
return class PropsChecker extends Component { | |
componentWillReceiveProps(nextProps) { | |
Object.keys(nextProps) | |
.filter(key => { | |
return nextProps[key] !== this.props[key]; | |
}) | |
.map(key => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isPalindrome = (string) => { | |
const _string = string.split(' ').join('').toLowerCase(); | |
const reverseString = _string.split('').reverse().join(''); | |
return _string === reverseString; | |
} | |
console.log(isPalindrome('Лазер боре хер обрезал')); // true | |
console.log(isPalindrome('Карл у Клары украл кораллы')); // false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
traverse = (obj, path, callback) -> | |
i = 0 | |
do (obj) -> | |
key = path[i] | |
i++ | |
if typeof obj[key] is 'object' | |
arguments.callee obj[key] | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validate(string) { | |
if (string[0] == ')') { | |
console.error(string + ' error: string should start with "("'); | |
return; | |
} | |
if (string.length % 2 !== 0) { | |
console.error(string + ' error: bracket number should be even'); | |
return; | |
} |