sortGrades WIP
sort list of rock climbing grades
by trentHarlem
HTML
<p>
climbing grades start at 'VB' (the easiest grade), <br>
and then go 'V0', 'V0+', 'V1', 'V2', 'V3' etc. up to 'V17'
</p>
JavaScript
// Work IN Progress
function sortGrades(lst) {
return lst.map(g => g.slice(1))
.sort((a, b) => a - b)
.map(g => `V${g}`)
}
// if(g==='B'){lst[0]='VB'}
// .filter(g=>g==='B') // returns "B"
// .filter(g=>g!=='B') // returns All except "B"
//Expected: ['VB', 'V0', 'V13', 'V14'], instead got: ['V13', 'V14', 'VB', 'V0']
//Expected: ['VB', 'V0', 'V0+', 'V2', 'V6', 'V16'], instead got: ['V0+', 'V0', 'V2', 'V16', 'VB', 'V6']
console.log(sortGrades(["V7", "V12", "V1"]),'expected', ["V1", "V7", "V12"])
console.log(sortGrades(['V13', 'V14', 'VB', 'V0']),'expected', ['VB', 'V0', 'V13', 'V14'])
console.log(sortGrades(['V0+', 'V0', 'V2', 'V16', 'VB', 'V6']),'expected', ['VB', 'V0', 'V0+', 'V2', 'V6', 'V16'])
// works for first example ["V7", "V12", "V1"]
const sortGradesArr = (lst) => lst.map(a => a.slice(1)).sort((a, b) => a - b).map(n => `V${n}`)