Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 27x 6x 6x 27x 3x 3x 18x 18x 1x 1x 1x 1x 1x 79x 9x 9x 70x 70x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 198x 198x 79x 79x 198x 59x 198x 139x 139x 198x 198x 1x 1x | /** * check whether element is a query */ const isOperationQuery = (element) => (element && element.query && element.query[0]); /** * check whether element is custom query append */ const isOperationToAppend = (element) => (isOperationQuery(element) && element.query[0].custom === 'append'); /** * check whether element contains number key */ const isElementNumber = (element) => (element && element.number !== undefined); /** * check whether nextElement indicates that current element should be an array */ const doesNextElementIndicateArray = (nextElement) => { if (isElementNumber(nextElement)) { return true; } if (isOperationToAppend(nextElement)) { return true; } return false; }; /** * return empty array or object depending on nextElement */ const setNonExistingElement = (nextElement) => { if (nextElement && doesNextElementIndicateArray(nextElement)) { return []; } return {}; }; /** * Set tempObject to deeper level, create if non-existent * @param {Object} element - input element with number, string or query key * @param {Object} object - tempObject containing the element at current location (from path) * @param {Object} nextElement - element of next iteration * @param {Boolean} isFinalElement - boolean to indicate whether it is the last element of path * @param {Any} val - value to be set at path * @returns {Object} tempObject with new element */ const setElement = (element, object, nextElement, isFinalElement, val) => { let temp = object; if (temp[element] === undefined) { temp[element] = setNonExistingElement(nextElement); } if (isFinalElement) { temp[element] = val; } else { temp = temp[element]; } return temp; }; module.exports = setElement; |