Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,155,940 members, 7,828,306 topics. Date: Wednesday, 15 May 2024 at 08:08 AM

Dairy Of Javascript Challenge - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / Dairy Of Javascript Challenge (1873 Views)

Who Has The Complete Version Of Javascript By Tutorials Point? / What are the Advantages Of Javascript Framework Over Vanilla Javascript / 30 Days Of Javascript Challenge {June 21 - July 20} (2) (3) (4)

(1) (2) (Reply) (Go Down)

Re: Dairy Of Javascript Challenge by Capslock01: 9:29am On Apr 14, 2022
LikeAking:
smiley

Haaa! I saw your code in the midnight. It worked for some position of elements in arrays. But not all cases probably because of the arrayOfNumber[0]. I was hoping to come and comment on it when I review proper so that it won't be that I'm too hasty without reviewing proper. Guess you saw it too.

But I was able to learn things from it.
I can still remember parts of the codes I'll try to write a modifications of the code soonest.
Re: Dairy Of Javascript Challenge by LikeAking: 12:17pm On Apr 14, 2022
Capslock01:


Haaa! I saw your code in the midnight. It worked for some position of elements in arrays. But not all cases probably because of the arrayOfNumber[0]. I was hoping to come and comment on it when I review proper so that it won't be that I'm too hasty without reviewing proper. Guess you saw it too.

But I was able to learn things from it.
I can still remember parts of the codes I'll try to write a modifications of the code soonest.

I observed that later. Its not flexible.

I will modify it.

Thanks
Re: Dairy Of Javascript Challenge by LikeAking: 3:18pm On Apr 14, 2022
Capslock01:


Haaa! I saw your code in the midnight. It worked for some position of elements in arrays. But not all cases probably because of the arrayOfNumber[0]. I was hoping to come and comment on it when I review proper so that it won't be that I'm too hasty without reviewing proper. Guess you saw it too.

But I was able to learn things from it.
I can still remember parts of the codes I'll try to write a modifications of the code soonest.

---See this 1--- Test on diff arrays, then get back to me, thank you.

function takeTwoInputs (arrayOfNumbers, targetNumber) {
for(const value of arrayOfNumbers){
let num = targetNumber - value;
if(arrayOfNumbers.indexOf(num) !== -1 && num + value === targetNumber){
return [arrayOfNumbers.indexOf(value),arrayOfNumbers.indexOf(num)]
}
else{
return [-1,-1];
}
}
}
console.log(takeTwoInputs([9,4,5,6,3,1,0], 10))
console.log(takeTwoInputs([2,45,9,6,1,53,9],47))
console.log(takeTwoInputs([4,9,3,5,0,14,10],100))
Re: Dairy Of Javascript Challenge by Capslock01: 7:28pm On Apr 14, 2022
LikeAking:


---See this 1--- Test on diff arrays, then get back to me, thank you.

function takeTwoInputs (arrayOfNumbers, targetNumber) {
for(const value of arrayOfNumbers){
let num = targetNumber - value;
if(arrayOfNumbers.indexOf(num) !== -1 && num + value === targetNumber){
return [arrayOfNumbers.indexOf(value),arrayOfNumbers.indexOf(num)]
}
else{
return [-1,-1];
}
}
}
console.log(takeTwoInputs([9,4,5,6,3,1,0], 10))
console.log(takeTwoInputs([2,45,9,6,1,53,9],47))
console.log(takeTwoInputs([4,9,3,5,0,14,10],100))


Great one boss!
It worked but not in all cases again when I switched the position of the 9 and 1 or maybe it's a fault from my end.
Thank you for taking out time to review. I'm really learning from your code.

Re: Dairy Of Javascript Challenge by Capslock01: 7:30pm On Apr 14, 2022
Don't know if there's any one following. I'm sorry for keeping you hanging, I was caught up with work.

Here's today's challenge.


Day 7

Create function that takes an array of unsorted numbers and sort them.

NB: You can't use the built-in sort function.

For example
[1,9,4,5,3,0] => your function [0,1,3,4,5,9]

[2,5,9,6,1,53,45] => your function [1,2,5,6,9,45,53]

[4,9,-3,5,0,-14,10] => your function [-14,-3,0,4,5,9,10]
Re: Dairy Of Javascript Challenge by Capslock01: 7:32pm On Apr 14, 2022
Capslock01:
Don't know if there's any one following. I'm sorry for keeping you hanging, I was caught up with work.

Here's today's challenge.


Day 7

Create function that takes an array of unsorted numbers and sort them.

NB: You can't use the built-in sort function.

For example
[1,9,4,5,3,0] => your function [0,1,3,4,5,9]

[2,5,9,6,1,53,45] => your function [1,2,5,6,9,45,53]

[4,9,-3,5,0,-14,10] => your function [-14,-3,0,4,5,9,10]





// Day 7

//Rearrange an unorganized Array

function arrangeArray (thatArrayToArrange) {
    for (let i = 1; i < thatArrayToArrange.length; i++) {
        for (let j = 0; j < i; j++) {
            if (thatArrayToArrange[i] < thatArrayToArrange[j]) {
                let temp = thatArrayToArrange[i];
                thatArrayToArrange[i] = thatArrayToArrange[j];
                thatArrayToArrange[j] = temp;
            }
        }
    }
    console.log(thatArrayToArrange);
}

arrangeArray([1,9,4,5,3,0]);
Re: Dairy Of Javascript Challenge by Altairx440: 7:38pm On Apr 14, 2022
Capslock01:
Don't know if there's any one following. I'm sorry for keeping you hanging, I was caught up with work.

Here's today's challenge.


Day 7

Create function that takes an array of unsorted numbers and sort them.

NB: You can't use the built-in sort function.

For example
[1,9,4,5,3,0] => your function [0,1,3,4,5,9]

[2,5,9,6,1,53,45] => your function [1,2,5,6,9,45,53]

[4,9,-3,5,0,-14,10] => your function [-14,-3,0,4,5,9,10]


I'm following, I just don't post my codes, I guess I'll have to start posting my codes.
Re: Dairy Of Javascript Challenge by Altairx440: 7:41pm On Apr 14, 2022
It is possible to indent properly in nairaland using "[<code>]content[/<code>]" tags, without the < & > brackets.
Re: Dairy Of Javascript Challenge by Altairx440: 7:47pm On Apr 14, 2022
LikeAking:


---See this 1--- Test on diff arrays, then get back to me, thank you.

function takeTwoInputs (arrayOfNumbers, targetNumber) {
for(const value of arrayOfNumbers){
let num = targetNumber - value;
if(arrayOfNumbers.indexOf(num) !== -1 && num + value === targetNumber){
return [arrayOfNumbers.indexOf(value),arrayOfNumbers.indexOf(num)]
}
else{
return [-1,-1];
}
}
}
console.log(takeTwoInputs([9,4,5,6,3,1,0], 10))
console.log(takeTwoInputs([2,45,9,6,1,53,9],47))
console.log(takeTwoInputs([4,9,3,5,0,14,10],100))

You can try using two loops to check for every possible pair, that should be easier, your code does not pass most testcases.
Re: Dairy Of Javascript Challenge by Altairx440: 8:10pm On Apr 14, 2022
Capslock01:
Don't know if there's any one following. I'm sorry for keeping you hanging, I was caught up with work.

Here's today's challenge.


Day 7

Create function that takes an array of unsorted numbers and sort them.

NB: You can't use the built-in sort function.

For example
[1,9,4,5,3,0] => your function [0,1,3,4,5,9]

[2,5,9,6,1,53,45] => your function [1,2,5,6,9,45,53]

[4,9,-3,5,0,-14,10] => your function [-14,-3,0,4,5,9,10]


day 7

I'm so used to writing python that javascript is now a pain, anyways, here's mine

let arr = [7,2,5,8,3,9,1,4,10]

const sortArray = arr => {
for (let i = 0; i < arr.length; i++) {
let minIndex = i;
for (let j = i; j < arr.length; j++) {
if (arr[minIndex] > arr[j]) {
minIndex = j;
}
}
let tmp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = tmp;
}
return arr;
}

console.log(sortArray(arr));
Re: Dairy Of Javascript Challenge by Capslock01: 9:16pm On Apr 14, 2022
Altairx440:

I'm following, I just don't post my codes, I guess I'll have to start posting my codes.

Thanks for following boss. I do appreciate.
Please be posting. It'll go a long way in helping to understand how things can be done better.

1 Like

Re: Dairy Of Javascript Challenge by Capslock01: 9:18pm On Apr 14, 2022
Altairx440:
It is possible to indent properly in nairaland using "[<code>]content[/<code>]" tags, without the < & > brackets.

Wow! Thanks boss. Never knew this.

I'd be using it in going forward. Thank once again boss.

Altairx440:

You can try using two loops to check for every possible pair, that should be easier, your code does not pass most testcases.

Yeah. True. Thank you for the two loops pointer.
Re: Dairy Of Javascript Challenge by Capslock01: 9:43pm On Apr 14, 2022
Altairx440:

day 7

I'm so used to writing python that javascript is now a pain, anyways, here's mine

let arr = [7,2,5,8,3,9,1,4,10]

const sortArray = arr => {
for (let i = 0; i < arr.length; i++) {
let min_index = i;
for (let j = i; j < arr.length; j++) {
if (arr[min_index] > arr[j]) {
min_index = j;
}
}
let tmp = arr[i];
arr[i] = arr[min_index];
arr[min_index] = tmp;
}
return arr;
}

console.log(sortArray(arr));

Great! Thanks for sharing boss.

It shows in your code that you're a Python writer. Some variables names (min_index...) are following Python way of naming. You know JavaScript mostly use CamelCase.


Care to share what you use Python for? Backend?
Re: Dairy Of Javascript Challenge by LikeAking: 10:06pm On Apr 14, 2022
Altairx440:

You can try using two loops to check for every possible pair, that should be easier, your code does not pass most testcases.

Checking!
Re: Dairy Of Javascript Challenge by Altairx440: 10:40pm On Apr 14, 2022
Capslock01:


Great! Thanks for sharing boss.

It shows in your code that you're a Python writer. Some variables names (min_index...) are following Python way of naming. You know JavaScript mostly use CamelCase.


Care to share what you use Python for? Backend?

Well not really, I just like python, its simplicity and elegance resonates with me but yeah I've built a project with python and flask, an auto corrected typing speed app though not from scratch.

I'm not even old enough to talk about jobs yet, but I like the idea of working remotely and node js seems to be standard so I also plan on learning it when the time comes, sorry I'm off topic.

I'll fix my code and please don't call me boss, you're the real boss.
Re: Dairy Of Javascript Challenge by Altairx440: 10:43pm On Apr 14, 2022
LikeAking:

Checking!
Good job, we'll be waiting.
Re: Dairy Of Javascript Challenge by Shedrach00(m): 7:57am On Apr 15, 2022
Well done Op.

This is a very good way to sharpen your coding skills.
Re: Dairy Of Javascript Challenge by 3exe3: 9:07am On Apr 15, 2022
qtguru:


They exist on Upworks, if you use them you have to search for gigs using those keywords, infact more platforms are jumping up these days.

Another is Webflow, there are so many Webflow gigs.

Really?? Learning web flow and figma currently.

Before I will apply let me finish with the project I got on hand.

So I can present something

(1) (2) (Reply)

Crystal Report In Vb.net / Use Hostgator Promo(coupon) Code And Enjoy 60% Discount ON NEW Hosting + Domain / Creating Best Programming Tutorials For Africans - Need Feedback

(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 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 41
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.