const arithmeticProgression = ({ length, a1 = 0, d = 1 }) =>
Array.from(
{ length },
(n, i) => a1 + i * d
);
const arr = arithmeticProgression({
length: 10,
a1: 6,
d: 3,
});
function* arithmeticProgression(a1, d, length) {
for (let i = 0; i < length; i++) {
yield a1 + i * d;
}
}
for (const n of arithmeticProgression(100, 10, 5)) {
console.log(n);
}
console.log(Array.from(arithmeticProgression(10, -7, 10)));
const closestTo = (dateToCompare, datesArray) => {
const buff = datesArray.filter(date => date >=dateToCompare).sort()
return buff.length ? buff[0] : undefined
}
($(element) as any).keydown(e => {
const {
target: {
selectionStart,
selectionEnd
},
keyCode: direction
} = e;
const htmlNode = $(this);
const inputValue = htmlNode.val();
const splittedTime = splitTime(inputValue);
const selectedValue = inputValue.substring(selectionStart, selectionEnd);
if (!selectedValue) { return; }
const Point = (x, y) => ({x, y});
const points = [Point(0, 2), Point(3, 5), Point(6, 10)];
const targetPoint = Point(selectionStart, selectionEnd);
const LEFT = 37;
const UP = 38;
const RIGHT = 39;
const DOWN = 40;
if ((direction === LEFT) || (direction === RIGHT)) {
e.preventDefault();
const index = points.findIndex(p => ((p.x === targetPoint.x) && (p.y === targetPoint.y)));
if (index === -1) { return; }
index += ((direction === LEFT) ? points.length : 1);
points.push(targetPoint);
const point = points[index % points.length];
this.setSelectionRange(point.x, point.y);
}
if ((direction === DOWN) || (direction === UP)) {
e.preventDefault();
const Actions = Enums.ValueActions;
const action = ((direction === DOWN) ? Actions.decrement : Actions. increment);
changeAppendix(splittedTime, selectedValue, htmlNode);
adjustTime(splittedTime, htmlNode, action, selectionStart, selectedValue);
this.setSelectionRange(selectionStart, selectionEnd);
}
});
autoFocus={true}
и отключать редактирование по событию blur. Так проблема с ненужным срабатыванием обработчика клика решится сама собой.export const getProductDetail = id => async dispatch => {
try {
dispatch(fetching());
const data = await ProductsService.getProductById(id);
dispatch(receiveData(data));
} catch (error) {
dispatch(fetchingError(error);
}
};
class ProductDetailContainer extends Component {
componentWillMount() {
const { match: { params: { id } }, getProductDetail } = this.props;
getProductDetail(id);
}
/* ... */
}
const mapStateToProps = state => ({
productDetail: state.products,
});
const matchDispatchToProps = {
getProductDetail,
}
export default connect(mapStateToProps, matchDispatchToProps)(ProductDetailContainer);
const set= new Set();
arrayOne.concat(arrayTwo).forEach(u => set.add(u));
arrayThree.concat(Array.from(set));
for (let j = 1; j <= this.players; j++) {
this.card.dataset.playerId = j; // а тут устанавливаем playerId. Но он у меня постоянно одинаковый
}
this.card.dataset.playerId = i <= this.players ? i : ((Math.random() * this.players | 0) + 1);
arr.map(function(subArray, a) {
subArray.map(function(row, b) {
row.map(function (value, c) {
if (value % 6 === 0) { // кратные шести, например
console.log(value, a, b , c)
}
})
})
})
https://jsfiddle.net/8yk66kbk/ function* rnd(n) {
var nums = [], i, randomIndex, itemAtIndex;
for( i=0; i<n; nums.push(i++));
for( i=n-1; i>=0; i--) {
randomIndex = Math.floor(Math.random()*(i+1));
itemAtIndex = nums[randomIndex];
nums[randomIndex] = nums[i];
nums[i] = itemAtIndex;
}
i = n - 1
while(i >= 0)
yield nums[i--];
}
var gen = rnd(10);
while(true) {
var v = gen.next();
if( v.done) break;
console.log(v.value);
}
console.log('Done!');
class Game {
// some stuff
createGame() {
this.players = [];
for (let i = 0; i < this.playersCount; i++) {
const player = new Player({
name: `Player ${i}`,
cards: this.createCards()
});
this.players.push(player);
}
}
createCards() {
// some stuff
}
// some stuff
}
const maxChar = str => {
const charObj = {};
let max = {char:'', count:''};
let maxChar = '';
for (let char of str) {
if (charObj[char]) {
charObj[char]++;
} else {
charObj[char] = 1;
}
if ( charObj[char] >= max.count ) {
max.char = char
max.count = charObj[char]
}
}
return max.char;
};
console.log( maxChar('abccccsddasdadwqwf'))