Extract Value

Vowel Count

Extracting value from nested arrays and key to find which array are left behind.

Example:
let arr = [[1,2,3],[2,3,4],[3,4,5],[4,5,6],[5,6,7]];
let key = 2;
console.log(extractValue(arr,key)) => [3, 4, 5, 6, 7]


let arr = [[1,2,3],[2,3,4],[3,4,5],[4,5,6],[5,6,7]];
let key = 1;
console.log(extractValue(arr,key)) => [2, 3, 4, 5, 6]

function extractValue(arr, key){
    return arr.reduce(function(acc,next){
        acc.push(next[key]);
        return acc;
    },[]);
}

let arr = [[1,2,3],[2,3,4],[3,4,5],[4,5,6],[5,6,7]];
let key = 2;

console.log(extractValue(arr,key)) [3, 4, 5, 6, 7]

let arr = [[1,2,3],[2,3,4],[3,4,5],[4,5,6],[5,6,7]];
let key = 1;
console.log(extractValue(arr,key)) [2, 3, 4, 5, 6]

We create a function called vowelCount with parameter called str and variable calledd vowels that is equal to every vowel “aeiou”

We return str.toLowerCase().split(‘’).reduce(function(acc,next) {})
We turn str to lowercase with toLowerCase JavaScript Method nad than we use split(‘’) like this to turn that string into an array. then we chain reduce wich returns callback function with parameters acc and next

if(vowels.indexOf(next) !== -1){ we check if vowels with .indexOf another JavaScript Method
The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present. -MDN

Then we check
if(acc[next]){
acc[next]++;
} else {
acc[next] = 1;
}
return acc;


If acc[next] is vowel and if it is we increase with acc[next]++
else if it only found vowel once acc[next] = 1;
In the end we return the acc

comments powered by Disqus