611 questions
-4
votes
3
answers
110
views
Are There Hidden Dangers in Using for...in in JavaScript? [closed]
I wrote the algorithm below and asked an AI to evaluate my solution.
//TESTS:
console.log(firstNonRepeatingCharacter('abacabaz')) //c
console.log(firstNonRepeatingCharacter('aabbccdeefgghijj')) //d
...
1
vote
1
answer
162
views
Why for...in with an object in typescript is typed as string
I hope this is not a silly question. Why when I use for (let property in myObject)... property is recognized by typescript as "string" instead of "keyof typeof myObject"? Is there ...
-2
votes
1
answer
41
views
Unexpected token, for in loop in react js
I'm new to React.
I know that comments should be received as an object, so I tried using a for...in loop to iterate over them. However, when I attempted to use the for...in loop, I encountered an ...
1
vote
1
answer
240
views
ERROR : " Trailing closure passed to parameter of type 'Binding<MapFeature?>' that does not accept a closure
import SwiftUI
import MapKit
import CoreLocation
struct ContentView: View {
@State private var position: MapCameraPosition = .userLocation(fallback: .automatic)
@State private var hazards: [(...
0
votes
1
answer
41
views
Using "for in" over a string to find a character but then not able to use the variable to reference another value
Still learning JS and confused over this
The below code gives out undefined as output when it should be "v" - am I missing something or using for-in over a string is the issue
let s="...
0
votes
3
answers
72
views
Why is this for... in loop not working when trying to loop keys nested inside objects?
I tried looping names of front-end developers nested inside of objects(refer to code) and when I printed it to console it says display is not defined.
var employees =
{
sales: {
...
-3
votes
3
answers
148
views
How are objects passed into a for...in loop in JavaScript?
I'm new to JavaScript and am learning about for...in loops and objects right now. I'm practicing with the following example:
let spaceship = {
crew: {
captain: {
name: 'Lily',
...
0
votes
1
answer
94
views
Unable to bound lifetime in for each loop using str.lines() function
I'm new to rust and i'm building an implementation of the grep command to learn this language.
I'm trying to create a function to match the search query in a case insensitive way, but i'm having ...
0
votes
2
answers
94
views
A for loop inside a for loop not executing after the first run
I've a dataset of firms with year from 1960-1989 and month (1-12) that looks like this.
PERMNO.
Year
Month
10057
1960
1
10057
1960
2
10057
1960
3
10057
1960
4
10057
1960
5
10057
1960
6
10057
1960
7
...
0
votes
1
answer
45
views
I am just confused in how the forin loop in js is used and why do we use const keyword in it
I have a object named user where one of the properties is skills and im trying to find a user who have the maximum no. of skills.
let maximum = 0;
let name;
for (const user in users) {
const len = ...
0
votes
1
answer
916
views
ReferenceError: string is not defined
I try to do iteration on object on nodejs using for in, on my local it's working just fine. but when i deploy it to web service, it pass an error.
but when i tried on my local it work just fine
const ...
0
votes
3
answers
420
views
Several approaches to converting values to lowercase not working
As part of a practice challenge for a bootcamp, I've been asked to: 'Fix the jumbled string values - replace them all with versions that are all lowercase'
I've tried several approaches based on ...
0
votes
2
answers
250
views
Keyword Declaration
Asked to:
'Iterate through the staff nested inside the restaurant object, and add their names to the staffNames array.'
My solution keeps getting rejected with this error:
'Use a declaration keyword ...
1
vote
1
answer
52
views
Trying to understand For In Loops [duplicate]
something is bugging me at the moment about For In Loops. I understand how to use them but what I can't seem to get my head around is.. Well, in this example:
const tree = {
name: 'Oak',
...
2
votes
3
answers
352
views
(Swift) Confused between a return value of a for-in loop within a function, and a return value that comes after the loop (within the function))
I am confused with the following code.
func allTestsPassed(tests: [Bool]) -> Bool {
for test in tests {
if test == false {
return false
}
}
return true
}
If ...