javascript 猜猜 - 功能编程

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 猜猜 - 功能编程相关的知识,希望对你有一定的参考价值。

// GUESS
function add (bookName) {
  var newBookList = bookList; 
  return newBookList.push(bookName);
  // Add your code above this line
}
// Add your code below this line
function remove (bookName) {
  if (bookList.indexOf(bookName) >= 0) {
    var newerBookList = bookList; 
    return newerBookList.splice(0, 1, bookName);
    
    // Add your code above this line
    }
}
// ACTUAL
function add (arr, bookName) {
  let newArr = [...arr];  // Copy the bookList array to a new array.
  newArr.push(bookName);  // Add bookName parameter to the end of the new array.
  return newArr; // Return the new array.
}

function remove (arr, bookName) {
  let newArr = [...arr];  // Copy the bookList array to a new array.
  if (newArr.indexOf(bookName) >= 0) {   // Check whether the bookName parameter is in new array.
    /.
    newArr.splice(newArr.indexOf(bookName), 1); // Remove the given paramater from the new array.
    return newArr; // Return the new array.
    }
}


//GUESS
// Add your code below this line
function filteredList (watchList, greaterThan8) {
  let newArray = [...watchList.filter(imdbRating => imdbRating >= 8)];
}
// ACTUAL
var filteredList = watchlist.map(function(e) {
  return {title: e["Title"], rating: e["imdbRating"]}
}).filter((e) => e.rating >= 8);

//GUESS
var s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback){
  var newArray = [];
  s.forEach(function(element){
    newArray.push(element < 90);
  });
  return newArray;

};
//ACTUAL
var s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback){
  var newArray = [];
  this.forEach(function(x) {
    if (callback(x) == true) {
      newArray.push(x);
    }
  return newArray;
};

以上是关于javascript 猜猜 - 功能编程的主要内容,如果未能解决你的问题,请参考以下文章

译文:10个超有用的HTML5功能

红包猜猜乐系统定制开发

javascript 视频代码 - “地图:JavaScript中功能编程的第2部分”

猜猜随机数为啥我无法输入 - python

课堂破冰游戏“猜猜他是谁”

javascript 功能编程概念