function cc(card) { switch(card){ case 2: case 3: case 4: case 5: case 6: count++; break; case 10: case "J": case "Q": case "K": case "A": count--; break; } if(count>0){ return count+" Bet"; }else if(count<=0){ return count+" Hold"; } }
225题:二维数组
如果你有一个二维数组,可以使用相同的逻辑,先遍历外面的数组,再遍历里面的子数组。下面是一个例子:
1 2 3 4 5 6 7 8
var arr = [ [1,2], [3,4], [5,6] ]; for (var i=0; i < arr.length; i++) { for (var j=0; j < arr[i].length; j++) { console.log(arr[i][j]); } }
function multiplyAll(arr) { var product = 1; // Only change code below this line for (var i = 0; i < arr.length; i++) { for (var j = 0; j < arr[i].length; j++) product *= arr[i][j]; } // Only change code above this line return product; }
// Modify values below to test your code multiplyAll([[1,2],[3,4],[5,6,7]]);
function lookUp(firstName, prop){ // Only change code below this line for (i = 0; i < contacts.length; i++) { if (contacts[i].firstName == firstName) { if (contacts[i].hasOwnProperty(prop)) { return contacts[i][prop]; } return "No such property"; } } return "No such contact"; // Only change code above this line }
// Change these values to test your function lookUp("Akira", "likes");