Functional (javascript) way to run a block of code if any of the list conditions are true [on hold]
up vote
-1
down vote
favorite
So say we have a list of strings that are keys of an object, and we want to see if any of these object properties are true, and if so, then execute a block of code.
I think it's obvious to use Array.some here, but should we filter the list first? That seems more explicit, but also wasteful.
Or is there another approach that is better than these two?
ASSUME
var propertyList = ['a', 'b', 'c'];
var obj = { a: false, b: true, c: true };
1.
propertyList.filter((key) => obj[key]).some(() => {
// code block to execute
return true;
});
2.
propertyList.some((key) => {
if (obj[key]) {
// execute code block
return true;
}
return false;
});
javascript functional-programming
put on hold as off-topic by Vogel612♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
up vote
-1
down vote
favorite
So say we have a list of strings that are keys of an object, and we want to see if any of these object properties are true, and if so, then execute a block of code.
I think it's obvious to use Array.some here, but should we filter the list first? That seems more explicit, but also wasteful.
Or is there another approach that is better than these two?
ASSUME
var propertyList = ['a', 'b', 'c'];
var obj = { a: false, b: true, c: true };
1.
propertyList.filter((key) => obj[key]).some(() => {
// code block to execute
return true;
});
2.
propertyList.some((key) => {
if (obj[key]) {
// execute code block
return true;
}
return false;
});
javascript functional-programming
put on hold as off-topic by Vogel612♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
1
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
– Vogel612♦
2 days ago
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
So say we have a list of strings that are keys of an object, and we want to see if any of these object properties are true, and if so, then execute a block of code.
I think it's obvious to use Array.some here, but should we filter the list first? That seems more explicit, but also wasteful.
Or is there another approach that is better than these two?
ASSUME
var propertyList = ['a', 'b', 'c'];
var obj = { a: false, b: true, c: true };
1.
propertyList.filter((key) => obj[key]).some(() => {
// code block to execute
return true;
});
2.
propertyList.some((key) => {
if (obj[key]) {
// execute code block
return true;
}
return false;
});
javascript functional-programming
So say we have a list of strings that are keys of an object, and we want to see if any of these object properties are true, and if so, then execute a block of code.
I think it's obvious to use Array.some here, but should we filter the list first? That seems more explicit, but also wasteful.
Or is there another approach that is better than these two?
ASSUME
var propertyList = ['a', 'b', 'c'];
var obj = { a: false, b: true, c: true };
1.
propertyList.filter((key) => obj[key]).some(() => {
// code block to execute
return true;
});
2.
propertyList.some((key) => {
if (obj[key]) {
// execute code block
return true;
}
return false;
});
javascript functional-programming
javascript functional-programming
edited 2 days ago
asked 2 days ago
Neil S
1093
1093
put on hold as off-topic by Vogel612♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by Vogel612♦ 2 days ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Lacks concrete context: Code Review requires concrete code from a project, with sufficient context for reviewers to understand how that code is used. Pseudocode, stub code, hypothetical code, obfuscated code, and generic best practices are outside the scope of this site." – Vogel612
If this question can be reworded to fit the rules in the help center, please edit the question.
1
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
– Vogel612♦
2 days ago
add a comment |
1
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
– Vogel612♦
2 days ago
1
1
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
– Vogel612♦
2 days ago
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
– Vogel612♦
2 days ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
1
I'm afraid this question does not match what this site is about. Code Review is about improving existing, working code. The example code that you have posted is not reviewable in this form because it leaves us guessing at your intentions. Unlike Stack Overflow, Code Review needs to look at concrete code in a real context. Please see Why is hypothetical example code off-topic for CR?
– Vogel612♦
2 days ago