Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,911 members, 7,802,961 topics. Date: Saturday, 20 April 2024 at 05:25 AM

Javascript Function To Java - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Javascript Function To Java (509 Views)

I Want To Java / Introduction To Java / Solutions To Java How To Program By Deitel, 9th Edition (2) (3) (4)

(1) (Reply) (Go Down)

Javascript Function To Java by islamics(m): 3:29pm On Dec 31, 2021
Hello,
I am following a YouTube video on dynamic programming. So the guy solve a problem on number of route available in a given grid that requires you to go right or down. He did the solution in JavaScript, I am having problem to replicate it in Java.
This is the JavaScript function:

const gridtravel = (m, n, memo = {} => {
const key = m + ',' + n;
if (key in memo) return memo[key];
if(m === 1 && n === 1) return 1;
if(m === 0 || n === 0) return 0;
memo[key] = gridtravel(m - 1, n, memo) + gridtravel(m, n - 1, memo);
return memo[key];
}


This is my trial in Java;

public static int gridTravel (m, n){
Map<String, Integer> memo = new Map<>();
String key = m + ',' + n;
if (memo.contains(key)) return memo.get(key);
if(m == 1 && n == 1) return 1;
if(m == 0 || n == 0) return 0;
memo.put(key, gridtravel(m - 1, n) + gridtravel(m, n - 1));
return memo.get(key);
}


I don't know how to replicate with the memo object use in JavaScript. The function is suppose to have two parameter of row and column.
This approach is trying to get an optimized solution
Cc
qtguru et al grin
Re: Javascript Function To Java by islamics(m): 11:14pm On Dec 31, 2021
Omo! No show here.
I have gotten a way around it sha. If only JS was strongly typed language, I would have known the types used.
Re: Javascript Function To Java by islamics(m): 11:18am On Sep 19, 2023
@ airsaylongcome Trust you are doing good.
Abeg na open source recommendation I want for Staff Invigilation scheduling (with regard to exams or so) and creating a journal management site.
For the journal management, I stumbled upon Open Journal System (OJS) and luckily, they have a youtube channel which I am already going through but no luck with that of the invigilation.

Thanks in anticipation of your response.
Re: Javascript Function To Java by airsaylongcome: 12:30pm On Sep 19, 2023
islamics:
@ airsaylongcome Trust you are doing good.
Abeg na open source recommendation I want for Staff Invigilation scheduling (with regard to exams or so) and creating a journal management site.
For the journal management, I stumbled upon Open Journal System (OJS) and luckily, they have a youtube channel which I am already going through but no luck with that of the invigilation.

Thanks in anticipation of your response.

www dot abc-roster dot com
This isn't open source but I've used it in a rush

www dot optaplanner dot org
Open source but has a learning curve

Also
github dot com/LandRover/StaffjoyV2

1 Like

Re: Javascript Function To Java by islamics(m): 8:21pm On Sep 19, 2023
airsaylongcome:


www dot abc-roster dot com
This isn't open source but I've used it in a rush

www dot optaplanner dot org
Open source but has a learning curve

Also
github dot com/LandRover/StaffjoyV2

Thanks very much Sir; this is well appreciated.

(1) (Reply)

.. / Rate This Website / What Most Programmers Won't Tell You About Solving Problems At Interviews

(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. 12
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.