AdjacentElementsProduct | CodeFights Intro Algorithm JavaScript Solution and Breakdown

AdjacentElementsProduct | CodeFights Intro Algorithm JavaScript Solution and Breakdown
Support our Community:
-Code, Tech and Caffeine Facebook Group:
– Looking for a a Bootcamp check out DevMountain’s program where housing is included with the tuition:

Tutoring, Mentoring and Course Walkthroughs available:

Thank you to my Patreon Supporters Below:
-Check out

Support me and visit my store at:

Internship, Part-Time, & Full time work for college students and recent grads:

Fan funding goes towards buying the equipment necessary to deliver 4k videos, 4k webcam, and a high quality microphone better audio. Any support is very appreciated!

My channel is here for aspiring programmers to learn easier and help debug any issues from the many great free resources available on the web.

Check out my other videos going over HTML, CSS, Ruby, Ruby on Rails, Java, JavaScript, Python, PHP, SQL, Command Line, BootStrap, jQuery, and WordPress from CodeCademy, CodeCombat, FreeCodecamp and more!

Please watch: “How I Became a Developer | My Developer Journey of the Last 3 Years | Ask a Dev”



Xem Thêm Bài Viết Khác:

11 thoughts on “AdjacentElementsProduct | CodeFights Intro Algorithm JavaScript Solution and Breakdown

  1. Can you please update your code like this?

    function adjacentElementsProduct(inputArray: number[]): number {
    let largestproduct = inputArray[0] * inputArray[inputArray.length-1];
    for(let i=0; i < inputArray.length-1; i++)
    const product = inputArray[i] * inputArray[i+1]
    largestproduct = largestproduct < product ? product :largestproduct;
    return largestproduct;
    console.log(adjacentElementsProduct([3, 6, -2, -5 ,7, 3]));

  2. How do you not get a rangeError at the last iteration of your loop? You are looking for an item at a spot that does not exist then: inputArray[i+1].
    Does JS not mind if you do that?

  3. This is my solution 🙂

    let arr = [0,1,2,3,4,5,4]; = function(i) {
    return this[i] * this[i+1];

    function maxProd(arr) {
    let productsArr = [];
    for (let i = 0; i < arr.length – 1; i++) {
    return Math.max(…productsArr);


Leave a Reply

Your email address will not be published. Required fields are marked *