Last active
November 22, 2022 17:04
-
-
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, …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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