Skip to content

Commit 5535103

Browse files
committed
reduce code suggestion
1 parent 61ea4ca commit 5535103

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

functions/array/in_array.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@ function in_array(needle, haystack, argStrict) {
1818

1919
var key = '',
2020
strict = !! argStrict;
21+
22+
if (strict) {
2123
for (key in haystack) {
22-
if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
24+
if (haystack[key] === needle) {
2325
return true;
2426
}
27+
}
28+
} else {
29+
for (key in haystack) {
30+
if (haystack[key] == needle) {
31+
return true;
32+
}
33+
}
2534
}
35+
2636
return false;
2737
}

0 commit comments

Comments
 (0)