Skip to content

Instantly share code, notes, and snippets.

View erkanzileli's full-sized avatar
:shipit:
what if

Erkan Zileli erkanzileli

:shipit:
what if
View GitHub Profile
@erkanzileli
erkanzileli / customMergeObjectsWithSameKeys.js
Created January 22, 2019 10:11
Merge objects of the same key name in arrays
var customMergeObjectsWithSameKeys = function (arr, key, mergeFunction) {
var _arr = []
arr.forEach(item => {
var index = _arr.findIndex(_item => _item[key] === item[key])
if (index === -1) {
_arr.push(item)
} else {
_arr[index] = mergeFunction(_arr[index], item)
}
})
@erkanzileli
erkanzileli / remove-a-node.java
Last active April 4, 2019 14:42
Delete an element from an array
public static Object[] delete(Object[] array, int index) {
Object[] newArray = new Object[array.length - 1];
for (int i = 0; i < array.length; i++) {
if (i == index)
continue;
newArray[i] = array[i];
}
return newArray;
}