Levelling

by Jimmy Chandra

JavaScript

(function() {
    'use strict';
    
    var levels = [
        { id: 1, max: 1000 },
        { id: 2, max: 2000 },
        { id: 3, max: null }
    ];
    
    levels.forEach(function(l, idx) {
        //pattern matches
        
        //if first entry...
        if (idx == 0) {
            console.log('Limit for level ' + l.id  + ' is up to ' + l.max);
            return;
        }
        
        //if has max...
        if (l.max) {
            console.log('Limit for level ' + l.id  + ' is more than ' + levels[idx - 1].max + ' and up to ' + l.max);
            return;
        }
        
        //else this must be the last entry
        console.log('Limit for level ' + l.id  + ' is more than ' + levels[idx - 1].max);
    });
    
}());