Skip to content

Instantly share code, notes, and snippets.

@CodeDotJS
Last active February 7, 2019 10:06

Revisions

  1. CodeDotJS revised this gist Feb 7, 2019. No changes.
  2. CodeDotJS created this gist Feb 4, 2019.
    25 changes: 25 additions & 0 deletions reverseVowelsOfString.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    'use strict';

    const reverseVowelString = s => {
    let str = s.split('');
    const voewls = ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'];
    const storeVowelsFromString = [];

    for (let i = 0; i <= str.length - 1; i++) {
    for (let j = 0; j <= voewls.length - 1; j++) {
    if (str[i] === voewls[j]) {
    storeVowelsFromString.push(str[i]);
    str[i] = '_';
    }
    }
    }

    const revStr = storeVowelsFromString.reverse();

    let index = 0;

    return str.map(a => a === "_" ? revStr[index++] : a).join('');
    };


    console.log(reverseVowelString('ENTREPRENEURIAL'));