Skip to content

Commit

Permalink
[Upd] Remove unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
blcham authored and LaChope committed Mar 23, 2024
1 parent 15eb48c commit 754442f
Showing 1 changed file with 0 additions and 56 deletions.
56 changes: 0 additions & 56 deletions src/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,59 +450,3 @@ export function dfsTraverseQuestionTree(questions, func) {
recursiveTraverse(q);
});
}

/**
* Filters an array of objects based on a key-value pair.
* @param {Array<Object>} array - The array of objects to filter.
* @param {string} key - The key to filter the objects by.
* @param {*} value - The value to match against the key.
* @param {boolean} [keyMustExist=true] - Indicates whether the key must exist in the objects. Defaults to true.
* @returns {Array<Object>} An array containing objects that match the given key-value pair.
*/
export function filterObjectsByKeyValuePair(array, key, value, keyMustExist = true) {
const matchingObjects = [];

if (!array || array.length === 0) {
return matchingObjects;
}
for (let obj of array) {
if (obj) {
if ((keyMustExist && obj.hasOwnProperty(key)) || !keyMustExist) {
if (!keyMustExist || obj[key] === value) {
matchingObjects.push(obj);
}
}
}
}

return matchingObjects;
}

/**
* Filters an array of objects based on a key-value pair within subquestions.
* @param {Array<Object>} array - The array of objects containing subquestions.
* @param {string} key - The key to filter the subquestions by.
* @param {*} value - The value to match against the key.
* @param {boolean} [keyMustExist=true] - Indicates whether the key must exist in the subquestions. Defaults to true.
* @returns {Array<Object>} An array containing subquestions that match the given key-value pair.
*/
export function filterSubquestionsByKeyValuePair(array, key, value, keyMustExist = true) {
const matchingSubquestions = [];

if (!array || array.length === 0) {
return matchingSubquestions;
}
for (let obj of array) {
if (obj && obj[SConstants.HAS_SUBQUESTION]) {
for (let subQuestion of obj[SConstants.HAS_SUBQUESTION]) {
if ((keyMustExist && subQuestion.hasOwnProperty(key)) || !keyMustExist) {
if (!keyMustExist || subQuestion[key] === value) {
matchingSubquestions.push(subQuestion);
}
}
}
}
}

return matchingSubquestions;
}

0 comments on commit 754442f

Please sign in to comment.