Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let arr = [1, 2, 3, 4, 5, 6]
- function solution(arr, n) {
- return arr.sort((a, b) => {
- let diff = Math.abs(n - a) - Math.abs(n - b)
- return diff == 0? b - a : diff
- })
- }
- console.log(solution(arr, 3))
Advertisement
Add Comment
Please, Sign In to add comment