UNPKG

logic-helper

Version:

This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

15 lines 465 B
function sortStringArray(arr) { // Sort the array in alphabetical order arr.sort(); // Loop through the array and compare adjacent elements for (let i = 0; i < arr.length - 1; i++) { // If the adjacent elements are the same, swap them if (arr[i] === arr[i + 1]) { [arr[i], arr[i + 1]] = [arr[i + 1], arr[i]]; // Decrement i to recheck the swapped element i--; } } return arr; } console.log(sortStringArray(1,5,1,2,3,6,5,1))