| [ Web Proxy ] |
| Viewing: https://raw.githubusercontent.com/anasmak04/Problem-solving-with-JavaScript/master/problem-46.js | [Back] [Original] |
// Sort an Array You must solve the problem without using any built-in functions
let sortArray = function(nums) {
let swapp
do {
swapp = false
for (let i = 0; i < nums.length; i++) {
if (nums[i] > nums[i + 1]) {
let temp = nums[i];
nums[i] = nums[i + 1];
nums[i + 1] = temp;
swapp = true
}
}
} while (swapp);
return nums
};
console.log(sortArray([5,9,2,-1,3,-126])) // [-126 , -1 , 2 ,3 , 5 , 9]
| Web Proxy Viewer | New URL | Original Page |