import {Component, OnInit} from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'untitled-intent';
price: string[] = ["11", "23", "45", "22","1","45","25","68","19"];
priceInt: number[] = [];
constructor() {
}
ngOnInit(): void {
console.log(`数据结果:${this.priceInt}`)
for (let i in this.price) {
this.priceInt[i] = Number(this.price[i]);
}
console.log(`数据结果two:${this.priceInt}`)
for (let i = 0; i < this.priceInt.length - 1; i++) {
for (let j = 0; j < this.priceInt.length - i - 1; j++) {
if (this.priceInt[j] > this.priceInt[j + 1]) {
let temp = this.priceInt[j];
this.priceInt[j] = this.priceInt[j + 1];
this.priceInt[j + 1] = temp;
}
}
}
console.log(`数据结果计划外three:${this.priceInt}`)
}
}
运行结果:
数据结果:
app.component.ts:21 数据结果two:11,23,45,22,1,45,25,68,19
app.component.ts:31 数据结果计划外three:1,11,19,22,23,25,45,45,68
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)