Skip to content

Commit 911a0fa

Browse files
committed
Update consolidated snippets
1 parent 4247224 commit 911a0fa

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

public/consolidated/javascript.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
"contributors": [],
1616
"code": "const flattenArray = (arr) => arr.flat(Infinity);\n\n// Usage:\nconst nestedArray = [1, [2, [3, [4]]]];\nconsole.log(flattenArray(nestedArray)); // Output: [1, 2, 3, 4]\n"
1717
},
18+
{
19+
"title": "Partition Array",
20+
"description": "Splits an array into two arrays based on a callback function.",
21+
"author": "Swaraj-Singh-30",
22+
"tags": [
23+
"javascript",
24+
"array",
25+
"partition",
26+
"reduce",
27+
"utility"
28+
],
29+
"contributors": [],
30+
"code": "const partition = (arr, callback) =>\n arr.reduce(\n ([pass, fail], elem) => (callback(elem) ? [[...pass, elem], fail] : [pass, [...fail, elem]]),\n [[], []]\n );\n\n// Usage:\nconst numbers = [1, 2, 3, 4, 5, 6];\nconst isEven = (n) => n % 2 === 0;\nconsole.log(partition(numbers, isEven)); // Output: [[2, 4, 6], [1, 3, 5]]\n"
31+
},
1832
{
1933
"title": "Remove Duplicates",
2034
"description": "Removes duplicate values from an array.",
@@ -1018,4 +1032,4 @@
10181032
}
10191033
]
10201034
}
1021-
]
1035+
]

0 commit comments

Comments
 (0)