please answer in httpsjsfiddlenet and sepereate the HTML fro

please answer in https://jsfiddle.net/

and sepereate the HTML from the Javascript, so it would be easy to understand for me

and also make sure code runs please!!!

Solution

Create random stringlist in JSfiddle

function randString(x){
    var s = \"\";
    while(s.length<x&&x>0){
        var r = Math.random();
        s+= (r<0.1?Math.floor(r*100):String.fromCharCode(Math.floor(r*26) + (r>0.5?97:65)));
    }
    return s;
}

document.getElementById(\"foo\").value = randString(10);

sort using two sorting techniques:

// sort an array of objects
/*
arrOfObj.sort(function (a, b) {
    return a.Name > b.Name;
});
*/

sortArrOfObjectsByParam(arrOfObj, \"Name\");
alert(\"ASCENDING: \" + arrOfObj[0].Name + \", \" + arrOfObj[1].Name + \", \" + arrOfObj[2].Name);

sortArrOfObjectsByParam(arrOfObj, \"Name\", false);
alert(\"DECENDING: \" + arrOfObj[0].Name + \", \" + arrOfObj[1].Name + \", \" + arrOfObj[2].Name);


/*
    Sorts an array of objects (note: sorts the original array and returns nothing)

    @arrToSort             array           javascript array of objects
    @strObjParamToSortBy   string          name of obj param to sort by, and an
    @sortAsc               bool (optional) sort ascending or decending (defaults to true and sorts in ascending order)
    returns                void            because the original array that gets passed in is sorted
*/
function sortArrOfObjectsByParam(arrToSort /* array */, strObjParamToSortBy /* string */, sortAscending /* bool(optional, defaults to true) */) {
    if(sortAscending == undefined) sortAscending = true; // default to true
  
    if(sortAscending) {
        arrToSort.sort(function (a, b) {
            return a[strObjParamToSortBy] > b[strObjParamToSortBy];
        });
    }
    else {
        arrToSort.sort(function (a, b) {
            return a[strObjParamToSortBy] < b[strObjParamToSortBy];
        });
    }
}

html:

$(\'#randomstring\').click(onClick);

$(\'#\').click(function() {
    sort1(5,6,1,2,3);
});

$(\'#sortmethod1\').click(onClick);

$(\'#\').click(function() {
    sort1(5,6,1,2,3);
});

$(\'#sortmethod2\').click(onClick);

$(\'#\').click(function() {
    sort1(5,6,1,2,3);
});?

$(\'#input\').click(onClick);

$(\'#\').click(function() {
    sort1(5,6,1,2,3);
});?

<textarea id=\'input\' style=\'width:100%;height:200px\'></textarea>

<input type=\"button\" id=\"button\" value=\"Randomstring\" />
<input type=\"button\" id=\"button2\" value=\"sort using method1\" />

<input type=\"button\" id=\"button\" value=\"sort using method2\" />
<input type=\"button\" id=\"button2\" value=\"inputstring\" />

please answer in https://jsfiddle.net/ and sepereate the HTML from the Javascript, so it would be easy to understand for me and also make sure code runs please!
please answer in https://jsfiddle.net/ and sepereate the HTML from the Javascript, so it would be easy to understand for me and also make sure code runs please!

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site