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.
Solution in JS:
function getNumberSwaps(arr, arrMap, sortedArr) {
let numberOfSwaps = 0;
for (let i = 0; i < sortedArr.length; i++) {
if (sortedArr[i] !== arr[i]) {
const tmp = arr[i];
const idxSource = arrMap[sortedArr[i]];
Lily's Homework
You are viewing a single comment's thread. Return to all comments →
Solution in JS: function getNumberSwaps(arr, arrMap, sortedArr) { let numberOfSwaps = 0; for (let i = 0; i < sortedArr.length; i++) { if (sortedArr[i] !== arr[i]) { const tmp = arr[i]; const idxSource = arrMap[sortedArr[i]];
}
function lilysHomework(arr) { const ascArr = arr.toSorted((a, b) => a - b); const descArr = arr.toSorted((a, b) => b - a);
}
`