Ticker

6/recent/ticker-posts

selection sort

<div id="app">
<input type="number" v-model="add">
<button @click="add_m">add</button>
<ul v-for="list in lists_c">
<li>{{list}}</li>
</ul>
</div>
view raw index.html hosted with ❤ by GitHub
new Vue({
data(){
return{
lists:[32,6,8,19,37,3,19,37,5],
add:0
}
},
computed:{
lists_c(){
var vm = this, arr = vm.lists;
for(var i = 0; i < arr.length; i++){
var lowest = i;
for(var j = i+1; j < arr.length; j++){
if(arr[j] < arr[lowest]){
lowest = j;
}
}
if(i !== lowest){
var temp = arr[i];
arr[i] = arr[lowest];
arr[lowest] = temp;
}
}
return arr;
}
},
methods:{
add_m(){
var vm = this
vm.lists.push(vm.add)
vm.add = 0
},
}
}).$mount('#app')
view raw script.js hosted with ❤ by GitHub
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>
view raw scripts hosted with ❤ by GitHub

Post a Comment

0 Comments