Skip to content

I want to add three new functions to the the custom function extension #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions functions/INVERSE_METRIX.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// @author Nwachukwu Ujubuonu https://github.com/Hemephelus/google-sheets-custom-function
/**
* Returns the inverse of a square metrix.
*
* @param {C1:D2} range The square metrix to invert.
*
* @return the inverse of a square metrix.
* @customfunction
*/
function INVERSE_METRIX(range) {

if(range[i].length !== range.length)return 'this is not a square metrix'

var temp,
N = range.length,
E = [];

for (var i = 0; i < N; i++)

E[i] = [];

for (i = 0; i < N; i++)

for (var j = 0; j < N; j++) {

E[i][j] = 0;
if (i == j)
E[i][j] = 1;

}

for (var k = 0; k < N; k++) {

temp = range[k][k];

for (var j = 0; j < N; j++) {

range[k][j] /= temp;
E[k][j] /= temp;
}

for (var i = k + 1; i < N; i++) {

temp = range[i][k];

for (var j = 0; j < N; j++) {

range[i][j] -= range[k][j] * temp;
E[i][j] -= E[k][j] * temp;

}

}

}

for (var k = N - 1; k > 0; k--) {

for (var i = k - 1; i >= 0; i--) {

temp = range[i][k];

for (var j = 0; j < N; j++) {

range[i][j] -= range[k][j] * temp;
E[i][j] -= E[k][j] * temp;

}

}

}

for (var i = 0; i < N; i++)

for (var j = 0; j < N; j++)

range[i][j] = E[i][j];
return range;

}
57 changes: 57 additions & 0 deletions functions/ROMAN_TO_NUMBER.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// @author Nwachukwu Ujubuonu https://github.com/Hemephelus/google-sheets-custom-function
/**
* Returns the values of the Roman Text as an Integer.
*
* @param {A2:A9 or "XXIII"} range The roman text to convert.
*
* @return the values of the Roman Text as an Integer.
* @customfunction
*/
function ROMAN_TO_NUMBER(range) {

let array = []

if(!Array.isArray(range))return ROM_TO_NUM_(range)


for (let i = 0; i < range.length; i++) {

array.push([ROM_TO_NUM_(range[i][0])] )

}
return array
};

function ROM_TO_NUM_(roman_text) {

let singleLetters = {
"I": 1,
"V": 5,
"X": 10,
"L": 50,
"C": 100,
"D": 500,
"M": 1000,
}


let total = 0
let val = 0

for (let i = 0; i < roman_text.length; i++) {

if (singleLetters[roman_text[i]] < singleLetters[roman_text[i + 1]]) {

val = singleLetters[roman_text[i + 1]] - singleLetters[roman_text[i]]
total += val
i++

} else {

total += singleLetters[roman_text[i]]

}

}
return total
};
27 changes: 27 additions & 0 deletions functions/SUPER_UNIQUE.gs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @author Nwachukwu Ujubuonu https://github.com/Hemephelus/google-sheets-custom-function
/**
* Returns unique rows in the provided source range and selected columns, discarding duplicates. Rows are returned in the order in which they first appear in the source range.
*
* @param {C1:D2} range The data to filter by unique entries.
* @param {"1,2"} cols The columns you want to filter by.
*
* @return Unique rows in the provided source range and selected columns.
* @customfunction
*/
function SUPER_UNIQUE(range,cols) {
cols = cols.replace(" ","").split(',')
let newRange = {}

for(let i = 0; i < range.length; i++){
let subRange = ''
for(let j = 0; j < cols.length; j++){
subRange = subRange+range[i][cols[j]-1]
}
newRange[subRange] = range[i]

}

return Object.values(newRange)


}