Skip to content

Instantly share code, notes, and snippets.

@hawksprite
Created October 21, 2020 16:47
Show Gist options
  • Save hawksprite/2047903fa08c56d0b30b1d3c63a93091 to your computer and use it in GitHub Desktop.
Save hawksprite/2047903fa08c56d0b30b1d3c63a93091 to your computer and use it in GitHub Desktop.
getPositionedAdjectives = (_data: any[], max: number, direction: number, nameMatch: string) => {
let data: any[] = [];
if (nameMatch === undefined) {
data = _data;
}
else {
for (let i = 0; i < _data.length; i++) {
const name: string = _data[i].name;
if (name.toLowerCase().includes(nameMatch.toLowerCase())) {
data.push(_data[i]);
}
}
}
if (data.length <= max) {
let buffer2 = '';
for (let i = 0; i < data.length; i++) {
// Check for an and to make gramatical sense
if (buffer2 !== '') {
buffer2 += ' and ';
}
buffer2 += data[i].adjective;
}
return buffer2;
}
let buffer = '';
for (let i = 0; i < max; i++) {
// Do we count from the start of the array, or the back?
const index = direction === 1 ? i : data.length - 1 - i;
// Check for an and to make gramatical sense
if (buffer !== '') {
buffer += ' and ';
}
buffer += data[index].adjective;
}
return buffer;
}
// Easiest, because the lowest difficulty objectives are at the top
getTopAdjectives = (data: any, max: number, nameMatch: any) => {
return this.getPositionedAdjectives(data, max, 1, nameMatch);
}
// Hardest because the highest difficulty objectives are at the bottom
getBottomAdjectives = (data: any, max: number, nameMatch: any) => {
return this.getPositionedAdjectives(data, max, -1, nameMatch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment