Open NBR-hugh opened 8 years ago
var motorBike = {
"wheels":4 ,
"engines":1,
"seats":5
};
this
this.wheels = 4;
var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 5;
};
var myCar = new Car();
,其中new必不可少;myCar.nickname = "xiaobai";
var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 5;
};
// Only change code below this line.
var myCar = new Car();
myCar.nickname = "xiaobai";
运行结果:
var Car = function(wheels,seats,engines) {
//Change this constructor
this.wheels = wheels;
this.seats = seats;
this.engines = engines;
};
//Try it out here
var myCar = new Car(8,9,10);
var Car = function() {
// this is a private variable
var speed = 10;
// these are public methods
this.accelerate = function(change) {
speed += change;
};
this.decelerate = function() {
speed -= 5;
};
this.getSpeed = function() {
return speed;
};
};
var oldArray = [1, 2, 3];
var timesFour = oldArray.map(function(val){
return val * 4;
});
console.log(timesFour); // returns [4, 8, 12]
console.log(oldArray); // returns [1, 2, 3]
The array method reduce is used to iterate through an array and condense it into one value.【将数组中元素压缩成一个数】
var singleVal = 2;
的值无影响,修改reduce的后面的0有影响,因为reduce对前者覆盖,而后者是与function 的结果想加,可看作初值var array = [4,5,6,7,8];
var singleVal = 2;
// Only change code below this line.
var singleVal = array.reduce(function(previousVla,currentVla){
return previousVla + currentVla;
},0);
array = array.filter(function(val) {
return val !== 5;
});
var array = [1, 12, 21, 2];
array.sort(function(a, b) {
return b - a ;
});
var array = [1,2,4,3,5,6,7];
var newArray = [];
// Only change code below this line.
newArray = array.reverse();
结果
newArray = oldArray.concat(otherArray);
var oldArray = [1,2,3];
var newArray = [];
var concatMe = [4,5,6];
// Only change code below this line.
newArray = oldArray.concat(concatMe);
运行结果
[1,2,3,4,5,6]
var string = "Split me into an array";
var array = [];
// Only change code below this line.
array = string.split(' ');
var joinMe = ["Split","me","into","an","array"];
var joinedString = '';
// Only change code below this line.
joinedString = joinMe.join(' ');
2016.10.28 10:40 END
TOTAL :2h10min
2016.10.28 8:30启动