We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
function processData(input) {
var numCounts = [];
var sortedArray = [];
input = input.split(" ");
input[0] = input[0].replace(/.*[0-9]\n/,"");
input = input.map(function(value) { return parseInt(value) });
input.forEach(function(value) {
numCounts[value] = numCounts[value] + 1 || 1;
});
//index of each numCounts value is the value!
for (var i = 0; i < numCounts.length; i++) {
//input each index numCounts[i] number of times into sortedArray
for (var j = 0; j < numCounts[i]; j++) {
sortedArray.push(i);
}
}
console.log(sortedArray.join(" "));
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Sort 2
You are viewing a single comment's thread. Return to all comments →
function processData(input) { var numCounts = []; var sortedArray = []; input = input.split(" "); input[0] = input[0].replace(/.*[0-9]\n/,""); input = input.map(function(value) { return parseInt(value) });
}