get help in general - we have more specialized help rooms here: https://gitter.im/FreeCodeCamp/home
hellow fam
i got the solution correct now
but i have a question
my first solution is this. i got the requirements correct except for the other one.bob instanceof Person should return true.
im getting this incorrect.
my first solution:
/*var first = firstAndLast.split(' ')[0];
var last = firstAndLast.split(' ')[1];
return {
getFullName: function() {
var fullName = first + ' ' + last;
return fullName;
},
getFirstName: function() {
return first;
},
getLastName: function() {
return last;
},
setFirstName: function(newFirst) {
first = newFirst;
},
setLastName: function(newLast) {
last = newLast;
},
setFullName: function(newFullname) {
first = newFullname.split(' ')[0];
last = newFullname.split(' ')[1];
//firstAndLast = newFullname;
}
};*/
var bob = new Person('Bob Ross');
bob.getFullName();
but on my 2nd solution
this is my 2nd solution i got everything correct. i just used the .this
keyword. i dont know why. i just followed the given sample that was initialize
var Person = function(firstAndLast) {
var fname = firstAndLast.split(' ')[0];
var lname = firstAndLast.split(' ')[1];
//Complete the method below and implement the others similarly
this.getFullName = function() {
var fullname = fname + ' ' + lname;
return fullname;
};
this.getFirstName = function() {
return fname;
};
this.getLastName = function() {
return lname;
};
this.setFirstName = function(newFirst) {
fname = newFirst;
};
this.setLastName = function(newLast) {
lname = newLast;
};
this.setFullName = function(newFull) {
fname = newFull.split(' ')[0];
lname = newFull.split(' ')[1];
};
};
var bob = new Person('Bob Ross');
bob.setFullName('bruh haa');
bob.getFullName();
darrenfj sends brownie points to @github-henry :sparkles: :thumbsup: :sparkles:
:cookie: 359 | @github-henry |http://www.freecodecamp.com/github-henry
darrenfj sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6566 | @manish-giri |http://www.freecodecamp.com/manish-giri
manish-giri sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2045 | @darrenfj |http://www.freecodecamp.com/darrenfj
github-henry sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2046 | @darrenfj |http://www.freecodecamp.com/darrenfj
darrenfj sends brownie points to @github-henry :sparkles: :thumbsup: :sparkles:
:cookie: 360 | @github-henry |http://www.freecodecamp.com/github-henry
darrenfj sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
var a = " ",
b = "-",
newStr = "";
for (var i = 1; i< str.length; i++){
if (str[i] === str[i].toUpperCase() && str[i-1] !== a){
newStr = str.slice(0,i);
}
}
return newStr; //AllThe-small
}
spinalCase('AllThe-small Things');
Can someone help me understand why this returns AllThe-small
and not All
? according to my conditions it should be looking for uppercase letters not preceeded by a space and then slice until the Uppercase letter...
i=0
so it is not checking for A
in the All
const fs = require("fs");
const path = require("path");
const ext = "extType."+(process.argv[3]);
const extname = path.extname(ext);
const directory = '/tmp/_learnyounode_3885';
fs.readdir( directory, function callback(err,files){
files.forEach(function(file) {
console.log(file);
});
});
T
and put in a space between All
and The
str[i-1] !== a
will be true for every character other than space
if (err) {
throw err;
}
uppercase letters
not preceeded by a space
in the example AllThe-small Things
that would be T
T
...)
fs.readdir( directory, function callback(err,files){
if (err){throw err;}
files.forEach(function(file) {
console.log(file);
});
});
function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
var a = " ",
b = "-",
newStr = "";
for (var i = 1; i< str.length; i++){
if (str[i] === str[i].toUpperCase() && str[i-1] !== a){
newStr = str.slice(0,i);
break;
}
}
return newStr; //AllThe-small
}
rscales02 sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1764 | @heroiczero |http://www.freecodecamp.com/heroiczero
bookofbash sends brownie points to @justin25 :sparkles: :thumbsup: :sparkles:
:cookie: 307 | @justin25 |http://www.freecodecamp.com/justin25
thisIsSpinalTap
becomes this-Is-Spinal-Tap
? I have figured out how to spot it with /[a-z][A-Z]/
but I can't think how to put those dashes
in
slice(0, str.search(/[a-z][A-Z]/)) + "-"
, but I can't figure out how to loop
through the str
for each case...
replace
with. Let me play with split
and concat
I guess...
rscales02 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 533 | @korzo |http://www.freecodecamp.com/korzo
str.replace(/your regex/g, '$1')
newStr = str.replace(matches, "$1 $2").replace(/\s/g, b).replace(/_/g, b)
was the magic line of pain in my dick :smile:
dmithun sends brownie points to @artbohr :sparkles: :thumbsup: :sparkles:
:cookie: 310 | @artbohr |http://www.freecodecamp.com/artbohr
function destroyer(arr) {
// Remove all the values
var args = Array.prototype.slice.call(arguments);
var newArray;
newArray=arr.filter(function(args){
for (var i=0; i < arr.length; i++) {for (var j=1; j < args.length; j++)
return arr[i] != args[j]; }
});
return newArray;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
function smallestCommons(arr) {
var nextArr = [],
total = arr[0];
arr = arr.sort(function(a,b){return b-a;});
for (var x = arr[0]; x >= arr[1]; x--){
nextArr.push(x);
} console.log(nextArr);
for (var y = 1; y < nextArr.length; y++){
total = nextArr[y]*total/gcd(nextArr[y],total);
}
return total;
}
function gcd(x,y){
var newArr = [];
for (var i = 1; i < y; i++){
if (x%i == 0 && y%i == 0)
newArr.push(i);
}
return newArr[newArr.length-1];
}
smallestCommons([5,1]);
Can someone tell me why nextArr
gets logged in my console 7 times the first 5 times they return identical [5, 4, 3, 2, 1]
, followed by [13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
and [23, 22, 21, 20, 19, 18]
var args = Array.prototype.slice.call(arguments/*, ???*/);
return arr.filter(function(element) {
// find if element is in args and return true/false
});
[1,5]
when I get identical logs in my console?
@rscales02
smallestCommons([1, 5]) should return a number.
smallestCommons([1, 5]) should return 60.
smallestCommons([5, 1]) should return 60.
smallestCommons([1, 13]) should return 360360.
smallestCommons([23, 18]) should return 6056820.
rscales02 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 535 | @korzo |http://www.freecodecamp.com/korzo
@rscales02 it was meant as answer to
why nextArr gets logged in my console 7 times
// 100x faster
function smallestCommons(arr) {
arr = arr.sort((a, b) => a-b);
var gcd = (a, b) => a % b === 0 ? b : gcd(b, a % b); // Greatest Common Divisor
return Array(arr[1] - arr[0] + 1)
.fill(0)
.map((e, i) => arr[0] + i) // Create range
.reduce((a, e) => (a * e)/gcd(a, e)); // Least Common Multiple
}
function smallestCommons(arr) {
arr = arr.sort((a, b) => a-b);
var range = Array(arr[1] - arr[0] + 1).fill(0).map((e, i) => arr[0] + i),
res;
do {
res = arr[1] * arr[0]++; // we don't need arr[0] anymore
} while(!range.every((e) => res % e === 0));
return res;
}
var gcd
does that do the same as my function gcd
?
function sumPrimes(num) {
return num < 2 ? 0 : isPrime(num)*num + sumPrimes(--num);
}
function isPrime(n, m) {
m = m || Math.floor(Math.sqrt(n));
return m < 2 ? true : n%m !== 0 && isPrime(n, --m);
}
sumPrimes(10);
function destroyer(arr) {
// Remove all the values
var args = Array.prototype.slice.call(arguments, 1);
var newArray;
newArray=arr.filter(function(element){
for (var i=0; i < args.length; i++)
{if (element.includes(args[i])) {return false;} else {return true;} }
});
return newArray;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
args[i]
will be 2 and 3
return num < 2 ? 0 : isPrime(num)*num + sumPrimes(--num);
to natural language for me I do not follow what it is actuall calling/testing/returning...
:
imply?
console.log(1 === 1 ? 'true': 'false');
return num < 2 ? 0 : isPrime(num)*num + sumPrimes(--num);
isPrime
returns a true
or false
, right?
isPrime(num)*num
sumPrimes(4) + sumPrimes(3) + sumPrimes(2) + sumPrimes(1)
isPrime(4)*4 + isPrime(3)*3 + isPrime(2)*2 + 0
function findElement(arr, func) {
var num = 0;
for (var i = 0; i< arr.length; i++){
num = arr[i];
if (func === true){
break;
}
}
return num;
}
findElement([1, 2, 3, 4], function(num){ return num % 2 === 0; });
am I calling func
incorrectly here?
func(arr[i])
return unefined
...
function findElement(arr, func) {
var num = 0;
for (var i = 0; i< arr.length; i++){
if (func(arr[i]) === true){
num = arr[i];
return num;
}
}
}
findElement([1, 3, 5, 9], function(num) { return num % 2 === 0; });
solves it
fucntion(num)
it can't understand what num is because it is undefined outside the function findelement
num = arr.filter(func())
func
?
arr.filter(function(arg){}):
function findElement(arr, func) {
return arr.filter(func)[0];
}
daddycardona sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 537 | @korzo |http://www.freecodecamp.com/korzo
function findElement(arr, func) {
if(func(arr[0]) === true) {
return arr[0];
}
if(arr.length === 1) {
return undefined;
}
return findElement(arr.slice(1), func);
}
let newStr = str.replace([/</g], changeIt);
change it is a function why is it not letting me console.log it?
for
loops were the one thing I actually understood how to use and now I have to get rid of them :frowning:
rscales02 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 538 | @korzo |http://www.freecodecamp.com/korzo
function convertHTML(str) {
var newStr = str.replace([/</g], changeIt);
console.log(newStr)
return;
}
function changeIt(words) {
console.log(words)
return 'it';
}
convertHTML("Hamburgers < Pizza < Tacos"); // thewhole code
changeIt
try adding ()
<
<
without the '
'` you get <
changeIt()
because it looks up nada in the parameters
str.replace([/</g], changeIt);
rscales02 sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
function changeIt(lol, wtf, lmao) {
console.log(lol, wtf, lmao);
}
function convertHTML(str) {
var newStr = str.replace([/</g], changeIt);
console.log(newStr)
function changeIt(words) {
console.log(arguments + 'words')
return 'it';
}
return newStr;
}
convertHTML("Hamburgers < Pizza < Tacos");
replac("<", changeIt )
and it does the first one so something is wrong with my regex
arguments
is argument object holding all parameters passed to function
[/</g]
/</g
/[<]/g
daddycardona sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
function destroyer(arr) {
// Remove all the values
var args = Array.prototype.slice.call(arguments, 1);
var newArray;
newArray=arr.filter(function(element){
for (var i=0; i < args.length; i++)
{if (element === args[i]) {return false;} else {return true;} }
});
return newArray;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
function destroyer(arr) {
// Remove all the values
var args = Array.prototype.slice.call(arguments, 1);
var newArray;
newArray=arr.filter(function(element){
if (args.includes(element)) {return false;} return true;
});
return newArray;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
mbmontana sends brownie points to @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 539 | @korzo |http://www.freecodecamp.com/korzo
var s1,j;
function reverseString(str) {
var j=str.length;
for(var i=0;i<j;i++)
{
s1[i]=str[j];
j--;
}
str=s1;
return str;
}
reverseString("hello");
s1
supposed to be an array?
undefined
undefined[0]
which throws TypeError
var s1 = []
at the beginning
kiranjd sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6567 | @manish-giri |http://www.freecodecamp.com/manish-giri
function reverseString(str) {
var s1 = [];
var j=str.length-1;
for(var i=0;i<str.length;i++)
{
s1[i]=str[j];
j--;
}
str=s1.join("");
return str;
}
reverseString("hello");
function reverseString(str) {
return str.split('').reverse().join('');
}
// Setup
function phoneticLookup(val) {
var result = "";
// Only change code below this line
var phoneticLookup = {
alpha:"Adams",
bravo:"Boston",
charlie:"Chicago",
delta:"Denver",
echo:"Easy",
foxtrot:"Frank"
};
// Only change code above this line <---- WHY I NEED TO CHANGE RETURN?
return phoneticLookup[val];
}
// Change this value to test
phoneticLookup("charlie");
aita-kane sends brownie points to @lydatech :sparkles: :thumbsup: :sparkles:
:star2: 2464 | @lydatech |http://www.freecodecamp.com/lydatech
result = phoneticLookup[val];
return result;
would not need to change
@tiagocorreiaalmeida
myStorage.car.inside.["glove box"]; // Change this line
at https://www.freecodecamp.org/challenges/accessing-nested-objects why this not working?
augustasv sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 359 | @tiagocorreiaalmeida |http://www.freecodecamp.com/tiagocorreiaalmeida
var gloveBoxContents = "myStorage.car.inside.[glove box]";