# Tagged: Arrays

## Find the first unique character in a given string or an array

Problem You are given an a string of characters including duplicates. You need to find the first non-repeating / unique character. input: foobar output: f input: aabbccdef output: d input: aabbcc output: ‘No Unique...

## Implement reduce in javascript

Reducing an array to a single value Often we have to iterate over the array by accessing multiple items at a time. For example, if you have to find the largest element in an...

## Find duplicates in an array using javascript

Problem : Given an array of positive integers find all the duplicate elements. Algorithm : Iterate over the array using forEach Find if there is a duplicate for the element using indexOf indexOf takes...

## Flatten nested array javascript

Problem : Given a nested array, flatten the given array. Input : [1, 2, 3, [4, 5], [6, [7, 8]]] Output : [1, 2, 3, 4, 5, 6, 7, 8] Logic : Iterate throgh...

## Find a pair of elements from an array whose sum equals a given number

Input: An array of n integers and given a number X. Expected output: All the unique pairs of elements (a, b), whose summation is equal to X. Example <pre>Given<span class=”pl-k”>var</span> unSortedArr <span class=”pl-k”>=</span> [<span...

## Calculate the average of a nested array

Problem description: The following nested array contains some invalid entries (which are not numbers). We also want to filter those entries in our average calculation. var nestedArray = [ 1, 2, 3, [4, 5,...

## Multi dimensional arrays in javascript

Problem description : The following function creates a 2-D array and initialize it with zeros. Find a bug in the code and propse a solution to it. The following gist shows the given code...