Input string, output vowels and consonants to log, separately but in orderOptimize calculation of distances...
Is exact Kanji stroke length important?
How to interpret the phrase "t’en a fait voir à toi"?
The One-Electron Universe postulate is true - what simple change can I make to change the whole universe?
What should I use for Mishna study?
I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?
Bob has never been a M before
Can I use my Chinese passport to enter China after I acquired another citizenship?
Can I rely on these GitHub repository files?
What was required to accept "troll"?
How do ultrasonic sensors differentiate between transmitted and received signals?
Why are on-board computers allowed to change controls without notifying the pilots?
How to check participants in at events?
Is a naturally all "male" species possible?
Is there any significance to the Valyrian Stone vault door of Qarth?
Is infinity mathematically observable?
For airliners, what prevents wing strikes on landing in bad weather?
What is Sitecore Managed Cloud?
Adding empty element to declared container without declaring type of element
In Star Trek IV, why did the Bounty go back to a time when whales were already rare?
My boss asked me to take a one-day class, then signs it up as a day off
Identify a stage play about a VR experience in which participants are encouraged to simulate performing horrific activities
Can a Gentile theist be saved?
Simple recursive Sudoku solver
How to prevent YouTube from showing already watched videos?
Input string, output vowels and consonants to log, separately but in order
Optimize calculation of distances between pairs of pointsHot 18 game (modified Blackjack)Generating a topographic stringFlow of Angular PromisesGenerating Heighway dragons in Unity C#Code Golf Challenge: Calculate Phi (not Pi)Rock, Paper, Scissors game in JavaScriptHackerrank Inherited CodePacket AssemblerTLE in JNEXT problem in SPOJ
$begingroup$
I completed a short coding challenge and just want to know if I should use shorter methods of which I am unaware, or make it more readable.
/*
*
* Complete the vowelsAndConsonants function.
* Print your output using 'console.log()'.
*/
function vowelsAndConsonants(s) {
var strConsonants = "";
var strVowels = "";
var i;
for (i in s) {
if (s.charAt(i) == "a" || s.charAt(i) == "e" || s.charAt(i) == "i" ||
s.charAt(i) == "o" || s.charAt(i) == "u") {
strVowels += s.charAt(i);
}
else if (s.charAt(i) != "a" || s.charAt(i) != "e" || s.charAt(i) != "i"
|| s.charAt(i) != "o" || s.charAt(i) != "u") {
strConsonants += s.charAt(i);
}
}
// console.log(strVowels);
i = 0;
for (i in strVowels) {
console.log(strVowels.charAt(i));
}
// console.log(strConsonants);
i = 0;
for (i in strConsonants) {
console.log(strConsonants.charAt(i));
}
}
javascript beginner programming-challenge
New contributor
Jacob Franklin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I completed a short coding challenge and just want to know if I should use shorter methods of which I am unaware, or make it more readable.
/*
*
* Complete the vowelsAndConsonants function.
* Print your output using 'console.log()'.
*/
function vowelsAndConsonants(s) {
var strConsonants = "";
var strVowels = "";
var i;
for (i in s) {
if (s.charAt(i) == "a" || s.charAt(i) == "e" || s.charAt(i) == "i" ||
s.charAt(i) == "o" || s.charAt(i) == "u") {
strVowels += s.charAt(i);
}
else if (s.charAt(i) != "a" || s.charAt(i) != "e" || s.charAt(i) != "i"
|| s.charAt(i) != "o" || s.charAt(i) != "u") {
strConsonants += s.charAt(i);
}
}
// console.log(strVowels);
i = 0;
for (i in strVowels) {
console.log(strVowels.charAt(i));
}
// console.log(strConsonants);
i = 0;
for (i in strConsonants) {
console.log(strConsonants.charAt(i));
}
}
javascript beginner programming-challenge
New contributor
Jacob Franklin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
I completed a short coding challenge and just want to know if I should use shorter methods of which I am unaware, or make it more readable.
/*
*
* Complete the vowelsAndConsonants function.
* Print your output using 'console.log()'.
*/
function vowelsAndConsonants(s) {
var strConsonants = "";
var strVowels = "";
var i;
for (i in s) {
if (s.charAt(i) == "a" || s.charAt(i) == "e" || s.charAt(i) == "i" ||
s.charAt(i) == "o" || s.charAt(i) == "u") {
strVowels += s.charAt(i);
}
else if (s.charAt(i) != "a" || s.charAt(i) != "e" || s.charAt(i) != "i"
|| s.charAt(i) != "o" || s.charAt(i) != "u") {
strConsonants += s.charAt(i);
}
}
// console.log(strVowels);
i = 0;
for (i in strVowels) {
console.log(strVowels.charAt(i));
}
// console.log(strConsonants);
i = 0;
for (i in strConsonants) {
console.log(strConsonants.charAt(i));
}
}
javascript beginner programming-challenge
New contributor
Jacob Franklin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
I completed a short coding challenge and just want to know if I should use shorter methods of which I am unaware, or make it more readable.
/*
*
* Complete the vowelsAndConsonants function.
* Print your output using 'console.log()'.
*/
function vowelsAndConsonants(s) {
var strConsonants = "";
var strVowels = "";
var i;
for (i in s) {
if (s.charAt(i) == "a" || s.charAt(i) == "e" || s.charAt(i) == "i" ||
s.charAt(i) == "o" || s.charAt(i) == "u") {
strVowels += s.charAt(i);
}
else if (s.charAt(i) != "a" || s.charAt(i) != "e" || s.charAt(i) != "i"
|| s.charAt(i) != "o" || s.charAt(i) != "u") {
strConsonants += s.charAt(i);
}
}
// console.log(strVowels);
i = 0;
for (i in strVowels) {
console.log(strVowels.charAt(i));
}
// console.log(strConsonants);
i = 0;
for (i in strConsonants) {
console.log(strConsonants.charAt(i));
}
}
javascript beginner programming-challenge
javascript beginner programming-challenge
New contributor
Jacob Franklin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Jacob Franklin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited yesterday
Jacob Franklin
New contributor
Jacob Franklin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 days ago
Jacob FranklinJacob Franklin
61
61
New contributor
Jacob Franklin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Jacob Franklin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Jacob Franklin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
The shorter method can be achieved using Regex and it is also the fastest according to JSBEN.CH:
var str = "The quick brown fox jumps over a lazy dog";
var vowels = str.match(/[aeiou]/gi);
var consonants = str.match(/[^aeiou$]/gi);
vowels.concat([''],consonants).forEach(function(k){
console.log(k);
});$endgroup$
$begingroup$
There's no reason to put the$into the character class of the regular expression. The indentation of the last 3 lines is a bit off, but apart from this: nice solution.
$endgroup$
– Roland Illig
5 hours ago
$begingroup$
You could also use theconstkeyword for the variable declarations. And I think the callback function in the forEach method would be even a bit nicer like thisforEach( consonant => { console.log(consonant)})
$endgroup$
– Dennis Fink
4 hours ago
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Jacob Franklin is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216086%2finput-string-output-vowels-and-consonants-to-log-separately-but-in-order%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
The shorter method can be achieved using Regex and it is also the fastest according to JSBEN.CH:
var str = "The quick brown fox jumps over a lazy dog";
var vowels = str.match(/[aeiou]/gi);
var consonants = str.match(/[^aeiou$]/gi);
vowels.concat([''],consonants).forEach(function(k){
console.log(k);
});$endgroup$
$begingroup$
There's no reason to put the$into the character class of the regular expression. The indentation of the last 3 lines is a bit off, but apart from this: nice solution.
$endgroup$
– Roland Illig
5 hours ago
$begingroup$
You could also use theconstkeyword for the variable declarations. And I think the callback function in the forEach method would be even a bit nicer like thisforEach( consonant => { console.log(consonant)})
$endgroup$
– Dennis Fink
4 hours ago
add a comment |
$begingroup$
The shorter method can be achieved using Regex and it is also the fastest according to JSBEN.CH:
var str = "The quick brown fox jumps over a lazy dog";
var vowels = str.match(/[aeiou]/gi);
var consonants = str.match(/[^aeiou$]/gi);
vowels.concat([''],consonants).forEach(function(k){
console.log(k);
});$endgroup$
$begingroup$
There's no reason to put the$into the character class of the regular expression. The indentation of the last 3 lines is a bit off, but apart from this: nice solution.
$endgroup$
– Roland Illig
5 hours ago
$begingroup$
You could also use theconstkeyword for the variable declarations. And I think the callback function in the forEach method would be even a bit nicer like thisforEach( consonant => { console.log(consonant)})
$endgroup$
– Dennis Fink
4 hours ago
add a comment |
$begingroup$
The shorter method can be achieved using Regex and it is also the fastest according to JSBEN.CH:
var str = "The quick brown fox jumps over a lazy dog";
var vowels = str.match(/[aeiou]/gi);
var consonants = str.match(/[^aeiou$]/gi);
vowels.concat([''],consonants).forEach(function(k){
console.log(k);
});$endgroup$
The shorter method can be achieved using Regex and it is also the fastest according to JSBEN.CH:
var str = "The quick brown fox jumps over a lazy dog";
var vowels = str.match(/[aeiou]/gi);
var consonants = str.match(/[^aeiou$]/gi);
vowels.concat([''],consonants).forEach(function(k){
console.log(k);
});var str = "The quick brown fox jumps over a lazy dog";
var vowels = str.match(/[aeiou]/gi);
var consonants = str.match(/[^aeiou$]/gi);
vowels.concat([''],consonants).forEach(function(k){
console.log(k);
});var str = "The quick brown fox jumps over a lazy dog";
var vowels = str.match(/[aeiou]/gi);
var consonants = str.match(/[^aeiou$]/gi);
vowels.concat([''],consonants).forEach(function(k){
console.log(k);
});answered 6 hours ago
Mawia HLMawia HL
190110
190110
$begingroup$
There's no reason to put the$into the character class of the regular expression. The indentation of the last 3 lines is a bit off, but apart from this: nice solution.
$endgroup$
– Roland Illig
5 hours ago
$begingroup$
You could also use theconstkeyword for the variable declarations. And I think the callback function in the forEach method would be even a bit nicer like thisforEach( consonant => { console.log(consonant)})
$endgroup$
– Dennis Fink
4 hours ago
add a comment |
$begingroup$
There's no reason to put the$into the character class of the regular expression. The indentation of the last 3 lines is a bit off, but apart from this: nice solution.
$endgroup$
– Roland Illig
5 hours ago
$begingroup$
You could also use theconstkeyword for the variable declarations. And I think the callback function in the forEach method would be even a bit nicer like thisforEach( consonant => { console.log(consonant)})
$endgroup$
– Dennis Fink
4 hours ago
$begingroup$
There's no reason to put the
$ into the character class of the regular expression. The indentation of the last 3 lines is a bit off, but apart from this: nice solution.$endgroup$
– Roland Illig
5 hours ago
$begingroup$
There's no reason to put the
$ into the character class of the regular expression. The indentation of the last 3 lines is a bit off, but apart from this: nice solution.$endgroup$
– Roland Illig
5 hours ago
$begingroup$
You could also use the
const keyword for the variable declarations. And I think the callback function in the forEach method would be even a bit nicer like this forEach( consonant => { console.log(consonant)})$endgroup$
– Dennis Fink
4 hours ago
$begingroup$
You could also use the
const keyword for the variable declarations. And I think the callback function in the forEach method would be even a bit nicer like this forEach( consonant => { console.log(consonant)})$endgroup$
– Dennis Fink
4 hours ago
add a comment |
Jacob Franklin is a new contributor. Be nice, and check out our Code of Conduct.
Jacob Franklin is a new contributor. Be nice, and check out our Code of Conduct.
Jacob Franklin is a new contributor. Be nice, and check out our Code of Conduct.
Jacob Franklin is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216086%2finput-string-output-vowels-and-consonants-to-log-separately-but-in-order%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown