recursion

Rearranging blocks of digits

戏子无情 提交于 2020-11-29 19:29:29
问题 I encountered a hard question I don't know the answer to: "Rearrange the digits from an integer in blocks of two with a recursive function" here's an example: Input: 123456 unsigned long pairinvPrint(unsigned long number) { printf("%d", number % 100); if ((number / 100) <= 99) { printf("%d", number / 100); } else { pairinv(number / 100); } } Output: 563412 More I/O Examples: 42 -> 42; 1234 -> 3412 However, the set circumstances to do this are hard (no loops, arrays, pointers, global- or

Traversing directories without using recursion?

北城余情 提交于 2020-11-29 04:44:59
问题 The Problem I need to write a simple software that, giving certain constraints, appends to a list a series of files. The user could choose between two "types" of directory: one with a * wildcard meaning it should also explore subdirectories and the classic one without wildcards that just get files present in that directory. What I'm doing Right now I'm doing the stupidest thing: import java.io.File; public class Eseguibile { private static void displayIt(File node){ System.out.println(node

How to loop trough a large object that has child objects and arrays?

此生再无相见时 提交于 2020-11-29 03:59:36
问题 I am developing an application where I need to implement simple search functionality, so I have this large object with child objects and arrays. Usually I access data in that object like this: list[id][day][show].title but now I need to check if that title is equal to some input value, so I created this function: getSimilarShows = (allShows, expectedShow) => { const titles = [] Object.values(Object.values(allShows)).map((days) => Object.values(days).map((items) => Object.values(items).map(

How to loop trough a large object that has child objects and arrays?

懵懂的女人 提交于 2020-11-29 03:59:14
问题 I am developing an application where I need to implement simple search functionality, so I have this large object with child objects and arrays. Usually I access data in that object like this: list[id][day][show].title but now I need to check if that title is equal to some input value, so I created this function: getSimilarShows = (allShows, expectedShow) => { const titles = [] Object.values(Object.values(allShows)).map((days) => Object.values(days).map((items) => Object.values(items).map(

How to loop trough a large object that has child objects and arrays?

本秂侑毒 提交于 2020-11-29 03:58:10
问题 I am developing an application where I need to implement simple search functionality, so I have this large object with child objects and arrays. Usually I access data in that object like this: list[id][day][show].title but now I need to check if that title is equal to some input value, so I created this function: getSimilarShows = (allShows, expectedShow) => { const titles = [] Object.values(Object.values(allShows)).map((days) => Object.values(days).map((items) => Object.values(items).map(

How to loop trough a large object that has child objects and arrays?

泄露秘密 提交于 2020-11-29 03:58:09
问题 I am developing an application where I need to implement simple search functionality, so I have this large object with child objects and arrays. Usually I access data in that object like this: list[id][day][show].title but now I need to check if that title is equal to some input value, so I created this function: getSimilarShows = (allShows, expectedShow) => { const titles = [] Object.values(Object.values(allShows)).map((days) => Object.values(days).map((items) => Object.values(items).map(

Javascript: recursive function returns undefined for existing value

淺唱寂寞╮ 提交于 2020-11-25 03:30:15
问题 I am trying to loop an array using a recursive function. The loop should stop and return the value of the key, if it matches a given regex pattern. The loop stops correctly when the condition is met. However, it only returns the key's value if the match occurs for the first key (index 0) in the array and returns 'undefined' for the rest. Where's my mistake? Here's the code to better illustrate: function loop(arr,i) { var i = i||0; if (/i/gim.test(arr[i])){ console.log("key value is now: " +