Last active
August 29, 2015 13:57
-
-
Save rickcnagy/9694657 to your computer and use it in GitHub Desktop.
Calculate a school's K12 Levels (PreK, Elem, etc) based on the lowest and highest age.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for Google Sheets | |
function calculateLevels() { | |
var youngColumn = 3; | |
var outputColumn = 5; | |
ss = SpreadsheetApp.getActiveSheet(); | |
var range = ss.getRange(2, youngColumn, ss.getLastRow(), 3); | |
var vals = range.getValues(); | |
for(var i = 0; i < vals.length; i++) { | |
var row = vals[i]; | |
row[2] = k12Levels(row[0], row[1]); | |
} | |
range.setValues(vals); | |
} | |
function k12Levels(lowAge, highAge) { | |
var ELEM_MIN = 6; | |
var MS_MIN = 11; | |
var HS_MIN = 14; | |
output = [] | |
if (lowAge < ELEM_MIN) output.push("PreK"); | |
if (lowAge < MS_MIN && highAge > ELEM_MIN) output.push("Elem") | |
if (lowAge < HS_MIN && highAge > MS_MIN) output.push("MS") | |
if (highAge > HS_MIN) output.push("HS") | |
return output.join(","); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment