nuxy / leetcode-238

Benchmark created on


Description

Product of Array Except Self

Setup

const productExceptSelf = function(nums) {
  const len = nums.length;
  const arr = [];

  for (let i = 0; i < len; i++) {
    const total = nums.reduce((accumulator, value, index) => {
      return (index !== i) ? (accumulator * value) : accumulator;
    });
  
    arr.push(Math.abs(total));
  }

  return arr;
};

Test runner

Ready to run.

Testing in
TestOps/sec
Test 1
productExceptSelf([1,2,3,4]); // [24,12,8,6]
ready
Test 2
productExceptSelf([-1,1,0,-3,3]); // [0,0,9,0,0]
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.