Day 2: Loops

HackerRank

by trentHarlem

JavaScript

/*
 * Complete the vowelsAndConsonants function.
 * Print your output using 'console.log()'.
 */
function vowelsAndConsonants(s) {
  'use strict';
  const vowels = ['a', 'e', 'i', 'o', 'u'];
  const isVowel = (x) => vowels.includes(x)
  const pre = [],post = []
  s.trim().split(' ').join('').split('').filter(l => isVowel(l)?pre.push(l):post.push(l))
  return pre.concat(...post).join(`\n`)
}

console.log(vowelsAndConsonants('javascript loops'))

  //const isCons = (x) => !vowels.includes(x)

  //.map(l => `${l}`) 
 // s.trim().split('').filter(l => isVowel(l)).map(l => `${l}`)
  //.join(`\n`)
  //.split('\n')
  //.filter(l => isCons(l)).map(l => l)

  /*    const str= s.trim().split(`\n`); 
     return str */