Look to examples:
- Wrong
const oldData = {
id: 1,
data: [
{id: 1, name: 'data1'},
{id: 2, name: 'data2'},
const formatDuration = ms => { | |
if (ms < 0) ms = -ms; | |
const time = { | |
day: Math.floor(ms / 86400000), | |
hour: Math.floor(ms / 3600000) % 24, | |
minute: Math.floor(ms / 60000) % 60, | |
second: Math.floor(ms / 1000) % 60, | |
millisecond: Math.floor(ms) % 1000 | |
}; | |
return Object.entries(time) |
const toKeyedArray = obj => { | |
const methods = { | |
map(target) { | |
return callback => | |
Object.keys(target).map(key => callback(target[key], key, target)); | |
}, | |
reduce(target) { | |
return (callback, accumulator) => | |
Object.keys(target).reduce( | |
(acc, key) => callback(acc, target[key], key, target), |
// This script is released to the public domain and may be used, modified and | |
// distributed without restrictions. Attribution not necessary but appreciated. | |
// Source: https://weeknumber.com/how-to/javascript | |
// Returns the ISO week of the date. | |
Date.prototype.getWeek = function() { | |
var date = new Date(this.getTime()); | |
date.setHours(0, 0, 0, 0); | |
// Thursday in current week decides the year. | |
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7); |
import React from 'react' | |
/** | |
* Returns function that provide props for component | |
* @param {ComponentType} Component component for provided props | |
* @param {Object} compProps props for component | |
* @returns {Function} provide function | |
*/ | |
export default function withProvideProps(Component, compProps) { | |
const wrapped = function WithProvideProps(props) { |
#!/bin/sh | |
if [ ! -e "$1" ]; then | |
echo "ERROR! File doesn't exists" | |
exit | |
fi | |
read -p "Enter output filename (default: new.gif): " output | |
(($output)) || output=new | |
read -p "Enter seconds output (default: 5s): " second |
"use strict"; | |
const Singleton = new (function () { | |
const single = this; | |
return function () { | |
return single; | |
}; | |
})(); | |
// Usage |
const curry = (func) => (...param) => { | |
if (func.length > param.length) { | |
// Если количество переданных аргументов меньше, чем ожидается функцией | |
const temp = func.bind(null, ...param); | |
return curry(temp); | |
} | |
return func(...param); | |
}; | |
function sum(param1, param2, param3) { |
Look to examples:
const oldData = {
id: 1,
data: [
{id: 1, name: 'data1'},
{id: 2, name: 'data2'},
import { mergeDeepWith } from 'ramda' | |
const withFunc = (left, right) => { | |
if (Array.isArray(left) && typeof left[0] === 'object') { | |
const array = left.length > right.length ? left : right | |
const temp = [] | |
for (let index = 0; index < array.length; index++) { | |
const item = mergeDeepWith(withFunc, left[index], right[index]) | |
temp.push(item) | |
} |
#!/bin/bash | |
set -e | |
CURRENT_COMMAND="yarn" | |
while getopts ":ny" opt_char; do | |
case $opt_char in | |
n) | |
CURRENT_COMMAND="npm" | |
;; |