Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,227,652 members, 8,071,142 topics. Date: Wednesday, 05 February 2025 at 03:54 PM |
Nairaland Forum / Science/Technology / Programming / Thread For Nairaland Algorithm Questions (6269 Views)
Public API For Nairaland / What Is Nairaland Algorithm? / A Thread For Tutorial On Python Programming (2) (3) (4)
(1) (2) (3) (4) (5) (Reply) (Go Down)
Re: Thread For Nairaland Algorithm Questions by Sheriman(m): 6:32pm On Jan 23, 2021 |
cixak95211:Lolsss.. Some Nigerians got talent and skills |
Re: Thread For Nairaland Algorithm Questions by cixak95211: 6:34pm On Jan 23, 2021 |
Ques 3: What is the problem with this block of code? What is the fix?
|
Re: Thread For Nairaland Algorithm Questions by Karleb(m): 6:53pm On Jan 23, 2021 |
cixak95211: I've not run the code but from what I see. Case 0 returns nothing. The switch statement will get stucked there. Solution, let case 0 return something. case amount > 5000 && amount <= 50000: I doubt if that is a valid case statement. Javascript will get confused at this stage. The logic should be wrapped around a parenthesis since it involves comparison. |
Re: Thread For Nairaland Algorithm Questions by naijasensei: 6:57pm On Jan 23, 2021 |
cixak95211: I agree with not using the additional variable 'temp' on line 42. As for line 23, the redundancy is intentional. As for the website for 20k guys, I reserve my comments - for now. |
Re: Thread For Nairaland Algorithm Questions by Phelumie300: 7:17pm On Jan 23, 2021 |
lahp: Yeah thanks for noticing I meant to use == @bolded could you be more specific |
Re: Thread For Nairaland Algorithm Questions by cixak95211: 7:21pm On Jan 23, 2021 |
Karleb: Case 0 returns 0. If you look well, you'll see the cases are stacked which is a valid switch expression Parenthesis are redundant. A smart code editor, once again, will remove the parentheses if you add it. Prettier will also remove it. Try again. |
Re: Thread For Nairaland Algorithm Questions by Karleb(m): 7:26pm On Jan 23, 2021 |
cixak95211: Let me get my editor. |
Re: Thread For Nairaland Algorithm Questions by Karleb(m): 7:38pm On Jan 23, 2021 |
Question, implement the doubly linked list data structure. The implementation should be within a class. |
Re: Thread For Nairaland Algorithm Questions by naijasensei: 8:36pm On Jan 23, 2021 |
cixak95211: From the way switch statements work, the expression within 'switch(expression)' is evaluated only once. That is this arrow function will always return either 0 (whenever amount is zero, or amount is undefined) or 50 for all other values because it ignores the comparison expressions in the two case statements following the first one. There are two possible solutions I can think of: 1. Use an if...else if...else construct. 2. Make the expression within 'switch(expr)' to always evaluate to true, then check your expressions within your case statements. const calculateFee = (amount) => { switch (true) { case amount === 0: case amount === undefined: return 0; case (amount > 0 && amount <= 5000): return 10; case (amount > 5000 && amount <= 50000): return 25; default: return 50; } }; const calculateFeeAlt = amount => { if (amount === 0 || amount === undefined) { return 0; } else if (amount > 0 && amount <= 5000) { return 10; } else if (amount > 5000 && amount <= 50000) { return 25; } else { return 50; } };
|
Re: Thread For Nairaland Algorithm Questions by cixak95211: 8:50pm On Jan 23, 2021 |
@naijasensei: Nailed it!!!! However case amount === 0: case amount === undefined: can be better rewritten as case !amount since ! will evaluate the same for falsey, null, zero and undefined same goes for amount === 0 || amount === undefined. |
Re: Thread For Nairaland Algorithm Questions by lahp(m): 12:09am On Jan 30, 2021 |
question: create a linked list data structure using OOP |
Re: Thread For Nairaland Algorithm Questions by Grandlord: 9:22am On Jan 30, 2021 |
Minds at work This is my hobby |
Re: Thread For Nairaland Algorithm Questions by Nobody: 9:43am On Jan 30, 2021 |
Shouldn't there be a standard algorithm syntax that explains the problem well? If there isn't then this threads name is bogus. |
Re: Thread For Nairaland Algorithm Questions by bunnae(f): 10:05pm On Jan 30, 2021 |
Grandlord:GrandLord, where you enter since? Happy new year |
Re: Thread For Nairaland Algorithm Questions by logicDcoder(m): 12:32am On Jan 31, 2021 |
Join This Thread To Solve More Complex Algorithmic Problems [url]www-nairaland-com.0.freebasics.com/6388476/nairaland-weekly-competitive-programming-competiton?iorg_service_id_internal=1646953538912597">https://https-www-nairaland-com.0.freebasics.com/6388476/nairaland-weekly-competitive-programming-competiton?iorg_service_id_internal=1646953538912597%3BAfrH0o9khtmhpHKa#98535658[/url] |
Re: Thread For Nairaland Algorithm Questions by Grandlord: 8:54am On Jan 31, 2021 |
bunnae:Bunnae my baby girl E don Tay sha. How ya side na? Wey our man icode2? Be like e don japa o |
Re: Thread For Nairaland Algorithm Questions by Grandlord: 8:56am On Jan 31, 2021 |
SegFault:Do you mean pseudocodes and flowcharts? Na extra work o 1 Like |
Re: Thread For Nairaland Algorithm Questions by Nobody: 8:58am On Jan 31, 2021 |
Grandlord:Only pseudocodes are enough, can't be reading code I don't understand. 1 Like |
Re: Thread For Nairaland Algorithm Questions by Grandlord: 9:05am On Jan 31, 2021 |
SegFault:I think pseudocodes will be too much to ask for here. Writing comments should be okay. |
Re: Thread For Nairaland Algorithm Questions by cbrass(m): 12:51pm On Feb 01, 2021 |
Karleb: Yea i aught to give you examples sef. actually this question not mine i just feel led to post |
Re: Thread For Nairaland Algorithm Questions by cbrass(m): 12:52pm On Feb 01, 2021 |
Grandlord: Comments is fine |
Re: Thread For Nairaland Algorithm Questions by Brukx(m): 12:20am On Feb 06, 2021 |
Exercise Write a pagination function. This function will convert a 1 dimensional array into a paginated 2 dimensional array. It will take 2 arguments. The first argument is the array to be paginated and the second one is the number of elements per pagination. Examples list=[1,2,3,4,5,6,7,8,9,10] paginate(list, 5) should return [[1,2,3,4,5], [6,7,8,9,10]] paginate(list,2) should return [[1,2], [3,4], [5,6], [7,8], [9,10]] paginate(list, 3) should return [[1,2,3], [4,5,6], [7,8,9], [10]] |
Re: Thread For Nairaland Algorithm Questions by Nobody: 12:53am On Feb 06, 2021 |
who will teach me programming oo |
Re: Thread For Nairaland Algorithm Questions by Deicide: 3:45pm On Jul 03, 2021 |
You are given an array and asked to find the element in the array that appears k times. eg arr = {1, 2, 2, 3, 3,3,4,4,4,4} fun = foo(arr, k) k = 2 ans = 2 |
Re: Thread For Nairaland Algorithm Questions by JFOD: 9:03pm On Jul 03, 2021 |
Brukx:
|
Re: Thread For Nairaland Algorithm Questions by JFOD: 12:26am On Jul 04, 2021 |
Deicide: Hmm, if I'm to solve this First attempt: Get the unique numbers loop through it get the count of each number Append it to a list /print it out if the count = 2 |
Re: Thread For Nairaland Algorithm Questions by Deicide: 1:06am On Jul 04, 2021 |
JFOD:Ok let's see implementation |
Re: Thread For Nairaland Algorithm Questions by JFOD: 1:18am On Jul 04, 2021 |
Deicide: I'll make use of python (it's easy to get the unique numbers using set) I'm assuming, list will be passed
|
Re: Thread For Nairaland Algorithm Questions by Deicide: 1:49pm On Jul 04, 2021 |
JFOD:did you test this code? am getting error for unique_num = {lst} unhashable type. though the solutions is correct. but then answer wouldn't be unique cause I have to remove {} |
Re: Thread For Nairaland Algorithm Questions by JFOD: 2:16pm On Jul 04, 2021 |
Deicide: I did not test the code. how to fix it #this will convert the list to set (set doesn't #allow duplicate values, so it will only have #unique numbers) unique_num = set(lst) |
Re: Thread For Nairaland Algorithm Questions by sharrp: 2:43pm On Jul 04, 2021 |
cbrass: You asked a wrong question , provided a wrong answer and with wrong input |
Re: Thread For Nairaland Algorithm Questions by sharrp: 2:44pm On Jul 04, 2021 |
Karleb: Just because he used the word pop and push doesn’t mean this requires a stack |
Nigeria’s Top Programmers And Developers As Ranked By Github 2016 / Script Or Software For Daily Contribution Biz / Data Science, AI & Machine Learning Tutorial Series
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2025 Oluwaseun Osewa. All rights reserved. See How To Advertise. 41 |