get help in general - we have more specialized help rooms here: https://gitter.im/FreeCodeCamp/home
const count = document.querySelector('.count')
[...]
minus.addEventListener('click', function() {
count.innerHTML = (count.innerHTML - 1);
});
gingerchew sends brownie points to @x140hu4 :sparkles: :thumbsup: :sparkles:
:cookie: 342 | @x140hu4 |http://www.freecodecamp.org/x140hu4
$(".minus").on("click", function(){});
darrenfj sends brownie points to @lydatech :sparkles: :thumbsup: :sparkles:
:star2: 2677 | @lydatech |http://www.freecodecamp.org/lydatech
{uniques: 'aehlstx', duplicates: 2}
'aehlstx'
and 2
are dynamically gotten
const removeDuplicates = word => {
// declare unique string and no of duplicates
let unique = '';
let noDupl = 0;
// create an object literal
const removeDuplicate = {
uniques : ${unique},
duplicates : ${noDupl}
};
gishy1 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9057 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
`${unique}`
b/w backticks
const removeDuplicates = word => {
// declare unique string and no of duplicates
let unique = '';
let noDupl = 0;
// create an object literal
const removeDuplicate = {
uniques : `${unique}`,
duplicates : `${noDupl}`
};
console.log(removeDuplicate);
}
removeDuplicates(); // {uniques: "", duplicates: "0"}
:cookie: 494 | @ezioda004 |http://www.freecodecamp.org/ezioda004
frediflexta sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
${noDupl}
to an int
noDupl
as a string if it is already a number and you want a number
Number(`${noDupl}`)
frediflexta sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
+string
return a number
number.toString()
Number(`${noDupl}`)
worked fine, thank you
frediflexta sends brownie points to @adelmahjoub :sparkles: :thumbsup: :sparkles:
:cookie: 664 | @adelmahjoub |http://www.freecodecamp.org/adelmahjoub
noDupl
is initially a number, you are returning it as a string, to convert it back to a number. I don't see why
let unique = ''; let noDupl = 0;
const removeDuplicates = (word, unique, noDupl)=> {
// declare unique string and no of duplicates
// create an object literal
const removeDuplicate = {
uniques : `${unique}`,
duplicates : Number(`${noDupl}`)
};
console.log(removeDuplicate);
}
removeDuplicates("Word", "somethingUnique", 2);
Example you can push it in via function dynamically
(word)
const removeDuplicates = word => {
// declare unique string and no of duplicates
let unique = '';
let noDupl = 0;
// create an object literal
let removeDuplicate = {
uniques : `${unique}`,
duplicates : Number(`${noDupl}`)
};
// split and sort the word
word.split('').sort().join('').replace(/[^A-Za-z0-9]/g, '');
// loop through the word, deleting duplicates
for (let i = 0; i < word.length; i++)
{
// note the 1st length of the word
let startlen = word.length;
if (word.lastIndexOf(word[i]) == word.indexOf(word[i]))
{
unique += word[i];
}
// note the new length of the word
let currentlen = unique.length;
noDupl += (startlen) - (currentlen);
}
console.log(removeDuplicate);
return removeDuplicate;
}
{ uniques: '', duplicates: 0 }
which means the my values are not updated
removeDuplicates('th#elex_ash?')
its suppose to return {uniques: 'aehlstx', duplicates: 2}
.replace()
isn't working
I put in a console.log after
word.split('').sort().join('').replace(/[^A-Za-z0-9]/g, '');
and I still get th#elex_ash?
@Frediflexta
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
The replace() method returns a new string with some or all matches of a pattern replaced by a replacement
word.split('').sort().join('').replace(/[^A-Za-z0-9]/g, '');
newword = word.split('').sort().join('').replace(/[^A-Za-z0-9]/g, '');
?
let replaced = word.replace(/[\W_]/g, '');
[\W_]
is equivalent to your current regex
_
in a string
_
is removed, I just ran my code against your example
.sort()
replace()
This is the sorting and replacement -
let replaced = [...word.replace(/[\W_]/g, '')].sort().join('');
and this is the removing duplicates -
let uniques = new Set(replaced);
duplicates
property
return {
uniques: [...uniques].join(''),
duplicates: replaced.length - uniques.size
}
let unique = '';
let noDupl = 0;
do i undeclare it? or is it good?
.replace
(which you should)
frediflexta sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6813 | @manish-giri |http://www.freecodecamp.org/manish-giri
duplicate
isn't parsing
// split and sort the word
let replacedword = [...word.replace(/[\W_]/g,'')].sort().join('');
// note the initial length of the word
let startlen = replacedword.length;
// iterate and remove duplicates
unique = new Set(replacedword);
// note the new length of the word
let currentlen = unique.length;
return {
uniques: [...unique].join(''),
duplicates: startlen - currentlen
};
}