JavaScript Coding Exercises For Beginners: Beginner Exercises Part 5

preview_player
Показать описание

This is the last in the 'beginners' exercises series that takes you through another 5 problems to solve with JavaScript.

Рекомендации по теме
Комментарии
Автор

for excercise 2 I used regex to check the matches:

const check = (str) => str.split("")
.filter(el => /[aeiou]/.test(el)).length

kremowydzien
Автор

I am learning js for more than 8 month and I still can't lose those exercices and this is only for beginners, I have only watched tutorials and didn't practice it by myself, I feel really depressed.

yassineel
Автор

Oh, this is what I was looking for! Javascript challenges for beginners! Thanks for your work man!

Elator
Автор

for exercise 1, you don't need to pass the comparing function to sort, you only need it for comparing numbers. So you could have put this instead:

and would have worked just fine.

davidsaso
Автор

Exercise 3 - I hope this is the simplest solution
function convertCoins(amount, coins = [25, 10, 5, 2, 1]) {
let totalCoins = [];
let j = 0;

while (amount > 0) {
if (amount >= coins[j]) {
amount -= coins[j];
totalCoins.push(coins[j]);
}

if (amount < coins[j]) {
j++;
}
}
return totalCoins;
}

ognjenpopovic
Автор

2:03 this also works
function a(str) {
return str.split('').sort().join('')
}
a("paper")

xc
Автор

Exercise 4. My solution is not that elegant but it works. I used a for loop and the array method includes:


const check = (str => {
const newArr = [];
const arr = str.split("");
for (let i = 0; i < arr.length; i++) {
if (!newArr.includes(arr[i])) {
newArr.push(arr[i]);
}
}
return newArr;
})

kremowydzien
Автор

// Exercise 5
firstNotRepeatedChar = str => {
return str
.split('')
.filter((value, index, array) => array.indexOf(value) ===
}

alpinestylecom
Автор

Did something very similar for #2:

const vowels = 'aouie'
const vowelCount = (str) => str.split('').filter(x => (vowels.split('')).indexOf(x) > -1).length;


// 2

Also your videos are dope!
Thank you so much!

tekqist
Автор

My solution for the vowels exercise 2:
const vowels = (str) => str.match(/[aeiou]/g).length;

hersheynaik
Автор

Exercise 3 - I used for and while loop combined with each other... :
function countCoins(money){
let coins = [25, 10, 5, 2, 1];
let result = [];
for (let i=0; i<coins.length; i++) {
while(money>=coins[i]){

= money-coins[i];
}
}
return result
}

saifeddine
Автор

Thank you so much, just subbed ! Btw are you planning on making another series for intermediate level?

monotoneguy
Автор

For exercise #2 it would be easier to do it this way:


}

sandoxs
Автор

my solution to #2:
const vowelCount = (str, vowel = ['a', 'e', 'i', 'o', 'u']) => vowel.filter(x => str.indexOf(x) != -1).length;
I didn't split the string and it still worked.

triptichhetri
Автор

Hi JDC,

The last exercise will return multiple values if the string has more than one unique values. For example, adbcacbdef will have expected output = e, f. I think we need to extract the first index of the final array, Or change the first filter to find.

huynhkequang
Автор

if you mind : your last exercice, about first no reapeted character, your function return all not repeated character instead of the first character only !
i did some test and : i found that the first 'Filter' must be Find. Please check that

fahdekarim
Автор

write-a javascript code to display a table of palindrome numbers between 100 and 500 through an html document.
Sir can you show how to do this program

GauravDeb
Автор

Hello, this was my solution to exercise 2


function countVowels(str){
str.split('')
let count = 0
for(let i = 0; i < str.length; i++){
if(str[i]=="a" || str[i]=="e" ||str[i]=="i" || str[i]=="o" || str[i]== "u"){
count++
}
}
return count;
}
4
3
*** Yes I know it's long, but it worked**

Ismael-jhbx
Автор

ex.II (a little different)
const countVowels = (str) =>
str.split('').filter(x => 'aeiou'.includes(x)).length

vitaliiparaskiv
Автор

This one is simpler: const strOrder = str => str.split ('').sort ().join ('')

anarjafarov