Add new solution version that directly returns (#34427)
In this case (that is quite typical) more complicated language features are not necessary.
This commit is contained in:
committed by
Nathaniel Suchy
parent
346b0a7ce1
commit
271b2c3434
@ -26,3 +26,12 @@ return arr.indexOf(elem) >= 0 ? true : false;
|
|||||||
}
|
}
|
||||||
console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
|
console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
|
||||||
```
|
```
|
||||||
|
- `Solution-3` demonstrates how the problem can be solved by directly returning result of the comparison.
|
||||||
|
|
||||||
|
## Solution-3:
|
||||||
|
```javascript
|
||||||
|
function quickCheck(arr, elem) {
|
||||||
|
return arr.indexOf(elem) != -1;
|
||||||
|
}
|
||||||
|
console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
|
||||||
|
```
|
||||||
|
Reference in New Issue
Block a user