xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
/* Write a JavaScript program that does each of the following things:
Defines a function called weirdArraySort() that accepts an array as an argument. This array may contain a mixture of single character strings and numbers. For example, this list would be valid input: [‘A’, 3, ‘X’, 1, ‘Q’]
Returns an array of letters sorted in reverse alphabetical order, followed by numbers sorted in ascending order. In the above example, the returned array would be: [“X”, “Q”, “A”, 1, 3]
*/
function weirdArraySort(inputArray){
numbers = [];
letters = [];
inputArray.forEach(function(i){
if (typeof i == "string"){
letters.push(i);
}
else {
numbers.push(i);
}
})
letters.sort();
letters.reverse();
numbers.sort();
return letters.concat(numbers);
}
array1 = ['A', 3, 'X', 1, 'Q']
console.log(weirdArraySort(array1))
</script>
</body>
https://d3js.org/d3.v4.min.js