Giter VIP home page Giter VIP logo

javascripthigherorderfunctionsexamples's Introduction

JavascriptHigherOrderFunctionsExamples

Few higher order functions in Javascript are map, filter, reduce, forEach.

map: creates an array by calling a specific function on each element present in the parent array. Generally map() method is used to iterate over an array and calling function on every element of array.

Syntax: array.map(function(currentValue, index, arr), thisValue)

filter: creates a new array filled with elements that pass a test provided by a function. The filter() method does not execute the function for empty elements. The filter() method does not change the original array.

Syntax: array.filter(function(currentValue, index, arr), thisValue)

reduce: executes a reducer function for array element. The reduce() method returns a single value: the function's accumulated result. The reduce() method does not execute the function for empty array elements. The reduce() method does not change the original array.

Syntax: array.reduce(function(total, currentValue, currentIndex, arr), initialValue)

forEach: The forEach() method is also used to loop through arrays, but it uses a function differently than the classic “for loop”. It passes a callback function for each element of an array together with the below parameters: Current Value (required): The value of the current array element Index (optional): The index number of the current element Array (optional): The array object the current element belongs to

Syntax: array.forEach(function(currentValue, index, arr), thisValue)

javascripthigherorderfunctionsexamples's People

Contributors

mounikakurapati17 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.