How to make another function aware of the loop name, so it can break it?

You see I have this code. (https://jsfiddle.net/kg4f2bu0/). Inside my iterate function I use a label for my loop, because I want to break it if it meets a condition. The condition gets checked inside the callback function. I want to break the for..of loop inside my callback function (compare). But it doesn’t recognise the statement… Read More How to make another function aware of the loop name, so it can break it?

Difference between for and for..of loops' output in a specific example

I have here two snippets of code, one using traditional for loop and the other using for…of loop. export function spinWords(words: string): string { const singleWords: string[] = words.split(‘ ‘); for (let i = 0; i < singleWords.length; i++) { if (singleWords[i].length >= 5) { singleWords[i] = singleWords[i].split(”).reverse().join(”); } } return singleWords.join(‘ ‘); } export… Read More Difference between for and for..of loops' output in a specific example

How to make name of users uniques by adding number of occurrence?

I’ve list of users: const users = [ { id: 1, name: “Leanne Graham”, phone: “1-770-736-8031 x56442”, }, { id: 2, name: “Ervin Howell”, phone: “010-692-6593 x09125”, }, { id: 3, name: “Leanne Graham”, phone: “1-463-123-4447”, }, { id: 4, name: “Leanne Graham”, phone: “493-170-9623 x156”, }, { id: 5, name: “Chelsey Dietrich”, phone: “(254)954-1289”,… Read More How to make name of users uniques by adding number of occurrence?

In JavaScript, Iterating over generator using for-of loop ignore return statement why?

Take a close look at code function* NinjaGenerator() { yield “yoshi”; return “Hattori”; } for (let ninja of NinjaGenerator()) { console.log(ninja); } // console log : yoshi Why "Hattori" is not logged ? Where as when we iterate over iterator using iterator.next() it show that value. function* NinjaGenerator() { yield “yoshi”; return “Hattori”; } let… Read More In JavaScript, Iterating over generator using for-of loop ignore return statement why?