Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

String Theory

// Description below the solution

const stringTheory = p => {
	let vowel = 0, consenant = 0, insertPV = "", invertCase = "", 
        splitP = p.split(""), dashedP = p.split(" ").join("-")

	splitP.forEach((letter, index) => {
		if(letter.match(/[aeiou]/gi)) {
			vowel += 1
			insertPV += `pv${letter}`
		}
		if(letter.match(/[^aeiou]/gi)) {
			if(letter.match(/[^" "]/g)) consenant += 1
			insertPV += letter
		}

		if(/[A-Z]/.test(letter)) invertCase += letter.toLowerCase()
		else invertCase += letter.toUpperCase()
	})

	const invertedCaseResult = invertCase.split(" ")
    							.reverse().join(" ")
	return `${vowel} ${consenant}::${invertedCaseResult}
			::${dashedP}::${insertPV}`
}

/*
      For a given sentence p, return the following:

      how many vowels and consonants p has, we do not count Y and W 
      as vowels
      p with reversed words order and reversed cases (any upper-case 
      letter will be lower-case and every lower-case letter will be 
      upper-case)
      every word in p separated by a dash ('-')
      p with inserted string "pv" before any vowel in the sentence
      Take into consideration that p can have any kind of characters.

      You have to return a string containing the above queries, 
      separated by double colon ("::")

      INPUT
      string    p

      OUTPUT
      string    combined_queries

      This is how combined_queries should look like:
      nr_vowels nr_consonants::reversed_p_with_reversed_cases
      ::every-word-in-p::p_wpvith_inspvertpved_strpving_pv

      EXAMPLE
      Input
      "ThIs is p"

      Output
      2 5::P IS tHiS::ThIs-is-p::ThpvIs pvis p
*/

// With love @kouqhar
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to append object in array javascript 
Javascript :: tailwindcsss next js change font 
Javascript :: event.propagation not working 
Javascript :: jquery sticky sidebar on scroll 
Javascript :: async map js 
Javascript :: string repeat in javascript 
Javascript :: javascript string error 
Javascript :: why did you render 
Javascript :: regex match first result only 
Javascript :: remove object property javascript es6 
Javascript :: momentjs docs 
Javascript :: react input cursor jump end 
Javascript :: javascript constant variable 
Javascript :: chart js x axis data bar 
Javascript :: javascript window screen 
Javascript :: js origin without port 
Javascript :: how to find last element of an array 
Javascript :: react window.addEventListener 
Javascript :: swr data fetching 
Javascript :: alertify js vue 
Javascript :: WebPack basic Configuration 
Javascript :: js array remove undefined values 
Javascript :: yarn globakl 
Javascript :: react native expo flatlist 
Javascript :: log error line node.js 
Javascript :: jquery ajax download file 
Javascript :: Using flat() method 
Javascript :: js add data in object 
Javascript :: convert div to image and download jquery 
Javascript :: jsonb_set 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =