We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/*************************************** * util ***************************************/ var getMin = function(list){ var min = { index: 0, value: list[0] }; list.forEach(function(target, index){ if(target < min.value){ min.index = index; min.value = target; } }); return min; }; /*************************************** * sort ***************************************/ var sortByMin = function(before){ var min, after = []; while(before.length > 0){ min = getMin(before); after.push(min.value); before.splice(min.index, 1); } return after; }; /*************************************** * main ***************************************/ var before = [0,9,3,4,6,7,8,2,1,5]; console.log('before : ' + before); var after = sortByMin(before); console.log('after : ' + after);
/*************************************** * util ***************************************/ var getMin = function(list){ var min = { index: 0, value: list[0] }; list.forEach(function(target, index){ if(target < min.value){ min.index = index; min.value = target; } }); return min; }; /*************************************** * sort ***************************************/ var sortByMin = function(before){ var min, after = []; while(before.length > 0){ min = getMin(before); after.push(min.value); before.splice(min.index, 1); } return after; }; /*************************************** main ***************************************/ var before = [0,9,3,4,6,7,8,2,1,5]; console.log('before : ' + before); var after = sortByMin(before); console.log('after : ' + after);
/*************************************** * util ***************************************/ var getMin = function(list){ var min = { index: 0, value: list[0] }; list.forEach(function(target, index){ if(target < min.value){ min.index = index; min.value = target; } }); return min; }; /*************************************** * sort ***************************************/ var sortByMin = function(before){ var min, after = []; while(before.length > 0){ min = getMin(before); after.push(min.value); before.splice(min.index, 1); } return after; }; /*************************************** main ***************************************/ var before = [0,9,3,4,6,7,8,2,1,5]; console.log('before : ' + before);
while(before.length > 0){ min = getMin(before); after.push(min.value); before.splice(min.index, 1); } return after; };
/***************************************
var after = sortByMin(before); console.log('after : ' + after);
https://codepen.io/Tkashiro/embed/LEYJBX/?height=300&theme-id=9575&default-tab=result&embed-version=2
The text was updated successfully, but these errors were encountered:
No branches or pull requests
date: 2014-11-16
title: Simple sort algorithm in JavaScript
slug: simple-sort-algorithm-in-javascript
lang: en-US
tags: [algorithm]
What is Simple sort algorithm ?
Code
Test
https://codepen.io/Tkashiro/embed/LEYJBX/?height=300&theme-id=9575&default-tab=result&embed-version=2
The text was updated successfully, but these errors were encountered: