JSFiddle - React, Tailwind, and code Playground

by michaelguild

JavaScript

var a = [23,45,30,80,160,2,3],
    mapping = {15:'foobar', 5: 'foo', 3: 'bar', 30 : 'foobars'};

var isEqual = function (numb, dict) {
    numb.forEach( function (value) {
        for (var key in dict) {
            if ( key == 30) {
                console.log( dict[key] + ' on ' + value);
            }
        }
    });
}

//isEqual(a, mapping);

var sort = function (list) {
    var preN = 0,
        newList = [];
    
    for( var i = 0; i <= list.length; i++) {
        var second = i + 1;
        compare(list[i], list[second]);
    }
        
    function compare (fN,sN) {
        console.log( fN + '' + sN);
        if (fN>sN) {
            newList.push(fN);
            preN = sN;
        } else {
            newList.push(sN);
            preN = fN;
        }
    }
    console.log(newList);
}

sort(a);