substring

finding all distinct substring of a string

偶尔善良 提交于 2020-07-30 03:15:10
问题 hello guys i was given homework problem where it asks me to find all distinct substring of a string. I have implemented a method which will tell you all the substrings of string but i need a help figuring out how to not count one which is already counted once as substring because assignment is to find distinct one. public int printSubstrings1(int length) { for(int i=0; i<text.length()-length+1;i++) { String sub = text.substring(i,length+i); counter++; } return counter; } here i am passing the

How can I check if an object contains at least one key whose value contains a substring in JavaScript?

情到浓时终转凉″ 提交于 2020-07-20 11:45:22
问题 I want to write a function that checks if an object has at least one value containing a substring. Something like this (pseudo-code): const userMatchesText = (text, user) => user.includes(text); The full structure of my objects ( So, for a user like the following: const user = { id: '123abc', info: { age: 12, bio: 'This is my bio' }, social: { chatName: 'Chris', friends: ['friend1', 'other friend'], blocks: ['Creep'] } //Etc. The objects I'm working with contain nested objects and arrays, etc