Skip to content

Instantly share code, notes, and snippets.

View codeallday31's full-sized avatar

Jhark codeallday31

View GitHub Profile
@codeallday31
codeallday31 / selectedObject.js
Last active July 17, 2023 08:38
return only the selected keys in object
const getData = (selectColumns = []) => {
let subset = object2
if (columnsOnly.length !== 0) {
subset = object2.map(obj =>
Object.fromEntries(
columnsOnly
.filter(key => key in obj)
.map(key => [key, obj[key]])
)
)
/**
* Emulates python's range() built-in. Returns an array of integers, counting
* up (or down) from start to end. Note that the range returned is up to, but
* NOT INCLUDING, end.
*.
* @param start integer from which to start counting. If the end parameter is
* not provided, this value is considered the end and start will
* be zero.
* @param end integer to which to count. If omitted, the function will count
* up from zero to the value of the start parameter. Note that
function elementGetStyle(element, style) {
var value = element.style[style];
if (!value) {
if (document.defaultView && document.defaultView.getComputedStyle) {
var css = document.defaultView.getComputedStyle(element, null);
value = css ? css.getPropertyValue(style) : null;
} else if (element.currentStyle) {
value = element.currentStyle[style];
}
}
function elementSetStyle(element, style) {
for (var name in style) {
var value = style[name];
if (value == null) value = "";
element.style[name] = value;
}
}
@codeallday31
codeallday31 / isArray.js
Last active July 17, 2023 08:41
checking value if array
function isArray(x) {
return ((typeof x) == "object") && (x["length"] != null);
}
function _group_by(list, key) {
const groupBy = (array, key) => {
// Return the end result
return array.reduce((result, currentValue) => {
// If an array already present for key, push it to the array. Else create an array and push the object
(result[currentValue[key]] = result[currentValue[key]] || []).push(
currentValue
);
// Return the current iteration `result` value, this will be taken as next iteration `result` value and accumulate
return result;