Skip to content

Instantly share code, notes, and snippets.

@shohagcsediu
Last active November 22, 2022 17:04
Show Gist options
  • Save shohagcsediu/0bf5116d4a86ac094550184abd8399e2 to your computer and use it in GitHub Desktop.
Save shohagcsediu/0bf5116d4a86ac094550184abd8399e2 to your computer and use it in GitHub Desktop.
Write a Javascript function named fixArray() that will take an array as an argument and return an array that has no duplicates and with elements in ascending order. // Testing code // Define your function fixArray() first let arr = [ 3, 26, 1, 2, 3, 44, 57, 87, 1 ]; let fixedArr = fixArray(arr); console.log(fixedArr); // result should be [1, 2, …
function fixArray(arr) {
let filtered = arr.filter((item, index) => arr.indexOf(item) === index);
return filtered.sort(function(a, b){return a-b})
}
let arr = [ 3, 26, 1, 2, 3, 44, 57, 87, 1 ];
let fixedArr = fixArray(arr);
console.log(fixedArr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment