const steps = Object.entries(answers).reduce((acc, [ key, val ]) => {
const question = questions.find(n => n.key === key);
const step = acc[val.step] = acc[val.step] || [];
step.push({
step: val.step,
question: { ...question.question },
answer: question.answer.values instanceof Object
? question.answer.values[val.answer].en
: val.answer,
});
return acc;
}, {});
const mapLangTitleByCode = code => ({
const titles = {
1: 'English',
2: 'Russian',
};
return titles[code] || 'unknown code';
});
<div className="profile-data">
<span>Language</span>
<span>{mapLangTitleByCode(data.q_lang)}</span>
</div>
<div className="profile-data">
<span>Sex</span>
<span>{data.q_sex === 1 ? 'Male' : 'Female'}</span>
</div>
isBlockNavButtons
отвечает за логику disable для тех кнопок. То есть если у нас элемент последний или первый, то мы блочим нужную нам кнопку.
dispatch({
type: `${CREATE_QUESTION}_BLOCK_BUTTON`,
payload: {
blockPreviousButton: elementIndex === 0,
blockNextButton: elementIndex === data.length - 1,
},
});
test: /\.(js|jsx)$/
function handleChange(e) {
return function (dispatch) {
dispatch({
type: PROMO_CODE,
payload: e.target.value
});
};
};
const reducer = (state = initialState, action) => {
switch (action.type) {
case USER_LOG:
return Object.assign({}, state, {
name: action.payload.name,
rating: [...state.data.rating, action.payload.rating]
})
default: return state;
}
};
const reducer = (state = initialState, action) => {
switch (action.type) {
case USER_LOG:
return {
...state,
name: action.payload.name,
rating: [...state.data.rating, action.payload.rating]
}
default: return state;
}
};
const initialState = {
data: {
name: 'Name',
rating: ["10", "9.1"]
},
};
const result = Object.entries(commonObj).map(([ k, v ]) => ({
objDataName: (objectData.find(n => n.key === k) || {}).name || null,
packageName: (packageData.find(n => n.id === v.package_id) || {}).title || null,
}));
const arrToObj = (arr, key, val) =>
arr.reduce((acc, n) => (acc[n[key]] = n[val], acc), {});
const objects = arrToObj(objectData, 'key', 'name');
const packages = arrToObj(packageData, 'id', 'title');
const result = Object.entries(commonObj).map(n => ({
objDataName: objects[n[0]] || null,
packageName: packages[n[1].package_id] || null,
}));
(function isNumberOne(one) {
'use strict';
function numberOne() {
if (this !== 1){
throw new Error('I`m not number one!');
} else {
console.log('I`m definitely number ONE!');
}
}
numberOne.call(one);
})(1);
function maxZeroSequence(arr) {
let iMin = 0;
let iMax = 0;
for (let i = 0; i < arr.length; i++) {
let sum = 0;
for (let j = i; j < arr.length; j++) {
if ((sum += arr[j]) === 0 && (iMax - iMin) <= (j - i + 1)) {
iMin = i;
iMax = j + 1;
}
}
}
return arr.slice(iMin, iMax);
}
function maxZeroSequence(arr) {
const sumIndices = Object.values(arr.reduce((acc, n, i) => {
const sum = acc[0] += n;
(acc[1][sum] = acc[1][sum] || [ i + 1 ])[1] = i + 1;
return acc;
}, [ 0, { 0: [ 0 ] } ])[1]);
return arr.slice(...sumIndices.reduce((max, n) => {
const diff1 = n[1] - n[0];
const diff2 = max[1] - max[0];
return diff1 > diff2 || (diff1 === diff2 && n[0] > max[0]) ? n : max;
}, [ 0, 0 ]));
}
NaN !== NaN // true
isNaN(undefined); // true
isNaN({}); // true
isNaN('test'); // true