CoDEVIANT #1 (3/21/19)

  • A: Not smart
  • B: Being an opera singer is a kind of a full time deal as well.
  • C: This is just a lick to me, cuh; if I learned I had the power to turn rain into titanium or gold, I’d be outta here. Sorry, not sorry.
Not me when it comes to coding
Me when things do work
We don’t have to be like this…we really don’t!

Instructions:

We want to know the index of the vowels in a given word, for example, there are two vowels in the word super (the second and fourth letters).

So given a string “super”, we should return a list of [2, 4].

Some examples:

Mmmm => []

Super => [2,4]

Apple => [1,5]

YoMama -> [1,2,4,6]

*NOTE: Vowels in this context refers to English Language Vowels — a e i o u y *

NOTE: this is indexed from [1..n] (not zero indexed!)

  1. We need to make a collection of things to look out for. Our vowels! a, e, i, o, u, y.
  2. We need a new array that starts out as empty to hold our answer.
  3. We need to turn the strings we receive as arguments to the function into arrays.
  4. Then we need to find where the matches are between the elements in our vowelArray and our strings-converted-into-arraysArrays.
  5. When there are matches, push them into an answerArray.
  6. Return the answer array. Profit.
let vowels = [‘a’,’A’,’e’,’E’,’i’,’I’,’o’,’O’,’u’,’U’,’y’, ‘Y’];
let answer = [];
let wordArray = word.split(‘’);
wordArray.forEach((letter)=>{//fun stuff coming soon!}
Adrian, what are you talking about? I know…I know.
wordArray.forEach((letter)=>{
vowels.forEach((target) => {
//fun stuff on the way
}
}
wordArray.forEach((letter)=>{
vowels.forEach((target) => {
if(letter == target) {
answer.push(wordArray.indexOf(letter) + 1);
}
}
}
function vowelIndices(word){let vowels = [‘a’,’e’,’i’,’o’,’u’,’y’];let answer = [];let wordArray = word.split(‘’);console.log(wordArray);        wordArray.forEach((letter) => {          vowels.forEach((target) => {             if(letter == target) {             answer.push(wordArray.indexOf(letter) + 1);            }          })       })return answer;}
let number = 0;let goodNumber = 0;
answer.push(goodNumber);
function vowelIndices(word){let vowels = [‘a’,’A’,’e’,’E’,’i’,’I’,’o’,’O’,’u’,’U’,’y’, ‘Y’];let answer = [];let number=0;let goodNumber=0;let wordArray = word.split(‘’);console.log(wordArray);wordArray.forEach((letter) => {    number ++;    vowels.forEach((target) => {         if(letter == target) {         goodNumber = number;         answer.push(goodNumber );         }     })})return answer;}
function vowelIndices(word) {var arr = [];for(var i = 0; i < word.length; i++) {   if(/[aeioyu]/i.test(word[i])) {  arr.push(i+1);   }}return arr;}
return ‘pig’[0]; //returns ‘p’

Complete the method which accepts an array of integers, and returns one of the following:

“yes, ascending” — if the numbers in the array are sorted in an ascending order

“yes, descending” — if the numbers in the array are sorted in a descending order

“no” — otherwise

You can assume the array will always be valid, and there will always be one correct answer.

  1. Set up a chan of if else statements that look at the current number and compare it to the next number in the sequence
  2. If the next number in the sequence is larger, return ‘yes, ascending’
  3. If the next number in the sequence is smaller, return ‘yes, descending’
  4. If not, then return ‘no’.
for(let i = 0; i < array.length; i++){currentNumber = array[i];}
if(currentNumber < array[i + 1] ) {return ‘yes, ascending’;} else if (currentNumber > array[i+1]){return ‘yes, descending’;} else {return ‘no’;}
function isSortedAndHow(array) {let currentNumber;for(let i = 0; i < array.length; i++){  currentNumber = array[i];  if(currentNumber < array[i+1]) {  return ‘yes, ascending’  } else if(currentNumber > array[i+1]) {  return ‘yes, descending’  } else {  return ‘no’;  } }}
Can’t win ’em all.
function isSortedAndHow(arr) {return arr.every((x,i)=>i==0||arr[i]>=arr[i-1])?’yes, ascending’:arr.every((x,i)=>i==0||arr[i]<=arr[i-1])?’yes, descending’:’no’}

arr.every( callback[, thisArg])

  1. Element = the element of the array currently being processed in the array
  2. Index = the index (or address) of the element being processed in the array
  3. Array = the array that every was called upon.
i==0 || arr[i] >= arr[i — 1]
aBitOfKnowledgeToEvaluate ? “If it is true” : “If it is false”
aBitOfKnowledgeToEvaluate ? “If it’s true”:Somethingelse ? “if the next thing is true”:”it was false”;
function isSortedAndHow(arr) {return arr.every((x,i)=>i==0||arr[i]>=arr[i-1])?’yes, ascending’:arr.every((x,i)=>i==0||arr[i]<=arr[i-1])?’yes, descending’:’no’}

--

--

--

is a web developer, opera singer, actor, and lover of cats. (adrian-rosales.tech)

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

New Beginnings (Coding Blog) - Week 1

Disrupting the data market: Interview with EXASOL’s CEO Aaron Auld

Measuring RPA: 10 Performance Metrics for Assessing Robotic Process Automation Benefits

The Basic SQL Commands(Part 1)

Steps to adopt DevOps

Employee Performance Management using Blockchain

Laravel Pluck() method

Microapps What, Why & How

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adrian Rosales

Adrian Rosales

is a web developer, opera singer, actor, and lover of cats. (adrian-rosales.tech)

More from Medium

Backtracking Made Easy

JavaScript Simplified — A Beginner’s Guide

Baby Steps to Understand The DOM

Day 4 of my journey to becoming a Unity game developer