Road to Genius: superior #65

Road to Genius: superior #65

Each day I solve several coding challenges and puzzles from Codr’s ranked mode. The goal is to reach genius rank, along the way I explain how I solve them. You do not need any programming background to get started, and you will learn a ton of new and interesting things as you go. function Node(val) {

Each day I solve several coding challenges and puzzles from Codr’s ranked mode. The goal is to reach genius rank, along the way I explain how I solve them. You do not need any programming background to get started, and you will learn a ton of new and interesting things as you go.

function Node(val) {
    this.val = val;
    this.next = null;
}
function myst(cur1, cur2) {
  if (cur1 === null || cur2 === null)
    return null;
  let head = new Node(0)
  let cur = head 
  let carry = 0 
  while (cur1 !== null || cur2 !== null) {
    let val1 = cur1 !== null ? cur1.val : 0
    let val2 = cur2 !== null ? cur2.val : 0
    let sum = val1 + val2 + carry
    let newNode = new Node(sum % 10) 
    carry = sum >= 10 ? 1 : 0 
    cur.next = newNode
    cur = cur.next
    if (cur1 !== null)
      cur1 = cur1.next
    if (cur2 !== null)
      cur2 = cur2.next
  }
  if (carry > 0)
    cur.next = new Node(carry)
  return head.next
};
let x = new Node(9)
x.next = new Node(6)
x.next.next = new Node(1)
let y = new Node(7)
y.next = new Node(8)
y.next.next = new Node(1)
let out = myst(x, y);
let A = out.val;
while (out.next) {
  A += out.val;
  out = out.next
}
// A = ? (number)

Here’s a challenge we haven’t encountered before. It seems to be related to linked lists, if you’re new to programming this is an important data structure to learn.

This code creates two separate linked lists x and y (at the end of the code). Then some mysterious function myst is called using x and y as arguments. Finally variable A is being computed depending on the output of myst.

A linked lists’ basic structure is a Node. A simple node contains some value and a pointer to the next node. A linked list is simply a chain of nodes:

Image for post

development computer-science javascript coding programming

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

6 Ways to Practice Your Coding Skills and Grow Your Career as a JavaScript Developer

6 min read ... Some of the highest-paid JavaScript developers make close to $500k/year ... actually need to learn many languages in the course of their career to ... Learn concepts professional developers need to advance their careers ...

Principles of Functional Programming in JavaScript That Will Make Your Coding Life Easier

Who else loves to write side-effects-free functions? I think we, as programmers, all do. Today, in this story, I will walk you through the basic principles of functional programming that will make your coding life easier.

13 Useful JavaScript Developer Tools for Writing High-Quality Code

Today I’m going to show you 13 well-know and popular tools to write better and cleaner JavaScript code. These are tools that I’m using right now on my JavaScript developer journey. So if you want to improve the quality of your projects, this list is for you.

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript. Bugs are born in many ways. Creating side effects is one of them. Some people say side effects are evil, some say they’re not.

Coding 101: Programming Language Building Blocks

This article will introduce the concepts and topics common to all programming languages, that beginners and experts must know!