PayPal Interview Question for Front-end Software Engineers


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
0
of 0 vote

Javascript .reduce example for calculating sum of an array:

arr = [1,2,3,4]

sum = arr.reduce((acc, val) => {
  return acc + val;
})

The same can be written in plain JS as:

arr = [1, 2, 3, 4];
sum = 0;
for(var i = 0; i < arr.length; i++) {
    sum += arr[i];
}

- skmohit05 December 08, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Array.prototype.reduce = function(func,initialValue){
let prev =initialValue
for(let i=0; i< this.length;i++) {
prev = func.apply(this, [prev, this[i]]) + 1
}
return prev
}

let ans = Array.from([1,2,3,4]).reduce((a,b) => a+b, 0)

console.log(ans)

- Messi10 January 22, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Array.prototype.reduce = function(func,initialValue){
  let prev =initialValue
  for(let i=0; i< this.length;i++) {
      prev = func.apply(this, [prev, this[i]]) + 1
  }
  return prev
}

let ans = Array.from([1,2,3,4]).reduce((a,b) => a+b, 0)

console.log(ans)

- Messi10 January 22, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Array.prototype.myReduce = function (callback, initValue) {
for(var i=0; i<this.length; i++){
if(initValue !== undefined){
initValue = callback(initValue, this[i], i, this)
}
else {
initValue = this[i]
}
}

return initValue;
}

console.log([1,2,3,4].myReduce((cal, val) => cal + val));
console.log([1,2,3,4].myReduce((cal, val) => cal + val, 3));

- Ambica July 22, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Array.prototype.myReduce = function (callback, initValue) {
  for(var i=0; i<this.length; i++){
      if(initValue !== undefined){
          initValue = callback(initValue, this[i], i, this)
      }
      else {
        initValue = this[i]
      }
  }

  return initValue;
}

console.log([1,2,3,4].myReduce((cal, val) => cal + val));
console.log([1,2,3,4].myReduce((cal, val) => cal + val, 3));

- Ambica JavaScript Solution July 22, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Array.prototype.myReduce = function(callback, initial) {
let element = this;
element.map((el)=>{
console.log(initial)
initial = initial !== undefined ? callback(initial,el) : el
})
return initial
}


console.log(arr.myReduce((acc, cu) =>{
return acc + cu
},1))

- Rajiv September 29, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Array.prototype.myReduce = function(callback, initial) {
let element = this;
element.map((el)=>{
console.log(initial)
initial = initial !== undefined ? callback(initial,el) : el
})
return initial
}


console.log(arr.myReduce((acc, cu) =>{
return acc + cu
},1))

- Rajiv September 29, 2020 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Array.prototype.myReduce = function(callback, initial) {
  let element = this;
  element.map((el)=>{
    console.log(initial)
    initial = initial !== undefined ? callback(initial,el) : el
  })
  return initial
}


console.log(arr.myReduce((acc, cu) =>{
  return acc + cu
},1))

- Rajiv September 29, 2020 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More