3つの簡単なH 5/Egret/JavaScript面接問題
1745 ワード
以下にEgretコード(Type Script)を使用する
1
2
3
1
/**
* k
* */
private question1(): void {
var i,j,k: number;
for(i = 0,j = 0;i < 10,j < 6;i++ ,j++) {
k = i + j;
}
console.log("k=" + k);
}
2
/**
* 10--100 10 , ,
* */
private question2(): void {
var t_arr_source: Array = [];
for(var i: number = 10;i <= 100;i++){
t_arr_source.push(i);
}
var length: number = 10;
var t_arr: Array = [];
for(var j: number = 0;j < length;j++){
var index: number = Math.floor(t_arr_source.length * Math.random());
t_arr = t_arr.concat(t_arr_source.splice(index,1));
}
t_arr.sort((a:number,b:number) => { return (a > b ? 1 : -1) });
console.log("t_arr=" + t_arr.toString());
}
3
/**
* [1,2,3,3,4,4,5,5,6,1,9,3,25,4] ,
* */
private question3(): void {
var t_arr_source: Array = [1,2,3,3,4,4,5,5,6,1,9,3,25,4];
var t_obj: any = {};
for(var i: number = 0;i < t_arr_source.length;i++){
if(t_obj[t_arr_source[i]]) {
t_obj[t_arr_source[i]] ++;
} else {
t_obj[t_arr_source[i]] = 1;
}
}
for(var p in t_obj) {
if(t_obj[p] == 1){
console.log(p);
}
}
}