This book provides a comprehensive exploration of programming in JavaScript, progressing from fundamental constructs to advanced applications. It opens with an introduction to the future of JavaScript and the importance of native language features, before moving into the essentials of variables, assignments, and basic operations. Conditional branching and loop structures are explained through numerous examples, highlighting their role in logic and algorithm design. Arrays are presented as versatile structures for data manipulation, with emphasis on traversal, transformations, and charting methods. These foundations extend naturally into multidimensional arrays and matrix operations, where concepts of alignment, summation, and transformation are demonstrated in detail. The book further develops functional programming skills by covering built-in methods, user-defined functions, recursion, and distinctions between procedures and functions. Object-oriented programming and JSON data handling are introduced as key tools for structuring information. Moderate examples expand on this foundation with sorting, permutations, statistics, and conversions, bridging toward complex demonstrations such as signal analysis, logic gate functions, and string alignment. The final chapters focus on randomness, Markov chains, and browser-specific features including local storage, file handling, charting, and graphical interfaces. With 226 worked examples, the text emphasizes the progression from simple principles to complex problem solving, offering conceptual clarity, practical code, and insight into JavaScript’s role in modern computing.
Note: The repositories below showcase a few demo algorithmic implementations drawn from the total of 226 algorithms presented in Coding Examples from Simple to Complex - Applications in JavaScript. Synthesis Lectures on Computer Science (Springer International Publishing, 2024). You may find these standalone implementations insightful:
- Ex. (85) - Horizontal chart with UTF characters proportional with max array
- Ex. (94) - 3D traversal with one for-loop using only arithmetic operators
- Ex. (140) - A simple scanner to find the output distribution
- Ex. (189) - Low level native sort and eliminate duplicates (I)
- Ex. (195) - Average, standard deviation and coefficient of variation
- Ex. (196) - Pearson correlation coefficient
- Ex. (198) - Vertical chart from array with random values at each run
- Ex. (209) - The general logic gate based on a map
- Ex. (210) - Decompose a matrix into multiple matrices based on unique values
- Ex. (213) - Count islands and calculate their percentage coverage
- 1.1 Future of JavaScript
- 1.2 The content is native
- Ex. (1) – Commenting inside code
- Ex. (2) – Naming variables
- Ex. (3) – Write your first Javascript program
- Ex. (4) – The meaning of “a = b”
- Ex. (5) – Difference between let and var declarations
- Ex. (6) – Basic mathematical operations
- Ex. (7) – The meaning of modulo operator
- Ex. (8) – The meaning of “a = a + 1”
- Ex. (9) – The aggregate assignment
- Ex. (10) – The post-decrement operator
- Ex. (11) – The pre-decrement operator
- Ex. (12) – The meaning of “+=” and “--a”
- Ex. (13) – Swap values
- Ex. (14) – Empty a variable
- Ex. (15) – Line continuation
- Ex. (16) – Formatted output
- Ex. (17) – If then else – conditional statements (I)
- Ex. (18) – If then else – conditional statements (II)
- Ex. (19) – If then else - conditional statements (III)
- Ex. (20) – If then elseif else - conditional statements
- Ex. (21) – Switch - conditional statements
- Ex. (22) – While loop
- Ex. (23) – Do while
- Ex. (24) – Simple for loop
- Ex. (25) – Reverse by subtraction from the upper limit
- Ex. (26) – The meaning of “i--”
- Ex. (27) – The meaning of “i--” vs “--i”
- Ex. (28) – Reverse by subtraction from the upper limit variable
- Ex. (29) – For loop summation
- Ex. (30) – Simple counter summation
- Ex. (31) – Sum all results of addition of 1 in a n×n cycle
- Ex. (32) – Sum all results of addition of 3 in a n×n cycle
- Ex. (33) – Sum all results of the multiplication between i and j
- Ex. (34) – Nested for loops and summation of counter variables
- Ex. (35) – Nested for loops and summation based on the inner counter
- Ex. (36) – Nested for loops & summation based on counters and upper limits (I)
- Ex. (37) – Nested for loops & summation based on counters and upper limits (II)
- Ex. (38) – Nested for loops & summation based on counters and upper limits (III)
- Ex. (39) – Show i and j coordinates at each step
- Ex. (40) – One for loop that simulates two for loops
- Ex. (41) – Array addition
- Ex. (42) – Extracting individual values from the elements of an array
- Ex. (43) – Adding elements
- Ex. (44) – Using array literals of different data type
- Ex. (45) – Accessing array elements
- Ex. (46) – Changing values in array elements - swap values or replace
- Ex. (47) – Extracting individual values from the elements of an array
- Ex. (48) – Array length
- Ex. (49) – Accessing the values from the components of an array
- Ex. (50) – Traverse a 1D array using a while loop
- Ex. (51) – Traverse a 1D array using a do while
- Ex. (52) – Traverse a 1D array using a for loop
- Ex. (53) – The for a in b
- Ex. (54) – Print all integers from array using a for loop
- Ex. (55) – Sum all values from array
- Ex. (56) – Multiplication involving a scalar and a 1D array
- Ex. (57) – Insert values into an array
- Ex. (58) – Insert ascending and descending integer values into arrays
- Ex. (59) – Add forward and reverse values and subtract max
- Ex. (60) – Pointless equilibrium
- Ex. (61) – Max value from array
- Ex. (62) – Min value from array
- Ex. (63) – Max value above two arrays of the same size
- Ex. (64) – Max value above two arrays of different sizes
- Ex. (65) – Which is bigger between n and n + 1?
- Ex. (66) – Which is bigger between n and n + 1? (optimization)
- Ex. (67) – Sum two arrays
- Ex. (68) – Simple array mapping
- Ex. (69) – Sum by coordinates (I)
- Ex. (70) – Sum by coordinates (II)
- Ex. (71) – Cutoff value
- Ex. (72) – Swap array elements by pattern
- Ex. (73) – Mix array based on pattern
- Ex. (74) – Swap array values
- Ex. (75) – Intermittent value swap
- Ex. (76) – Reverse string
- Ex. (77) – The welding of array values
- Ex. (78) – Static modulo - fill up array with modulo results
- Ex. (79) – Dynamic modulo - take a[i] modulo j
- Ex. (80) – Convert a string to an array
- Ex. (81) – The rule of three simples
- Ex. (82) – Average, standard deviation and coefficient of variation
- Ex. (83) – Horizontal chart from ASCII characters
- Ex. (84) – Horizontal chart with bars proportional with max from array
- Ex. (85) – Horizontal chart with UTF characters proportional with max array
- Ex. (86) – Accessing the elements of matrix A
- Ex. (87) – Accessing the elements of matrix A using nested for loops
- Ex. (88) – Traverse a matrix with a single for loop (I)
- Ex. (89) – Traverse a matrix with a single for loop (II)
- Ex. (90) – Accessing the elements of a 3D array
- Ex. (91) – Traverse a 3D object with a single for loop
- Ex. (92) – Traverse a 2D object with a single for loop and integer division
- Ex. (93) – Traverse a 2D object with a single for loop using arithmetic operators
- Ex. (94) – 3D traversal with one for-loop using only arithmetic operators
- Ex. (95) – How many 1's in matrix
- Ex. (96) – Sum all values from matrix elements
- Ex. (97) – Show matrix content
- Ex. (98) – Multiplication involving a scalar and a matrix
- Ex. (99) – Sum all values from the rows of the matrix
- Ex. (100) – Sum all values from the columns of the matrix
- Ex. (101) – Find max and min on columns and rows of a matrix
- Ex. (102) – Multiply all values from the columns / rows and store them in array
- Ex. (103) – Sum all values from the right diagonal of the square matrix
- Ex. (104) – Sum all values from the left diagonal of the square matrix
- Ex. (105) – Sum all values from the left and right diagonal of a square matrix
- Ex. (106) – Sum all values from the left and right diagonal by using conditions
- Ex. (107) – Show bottom–left part of the matrix
- Ex. (108) – Show bottom–left part of the matrix and flip horizontal
- Ex. (109) – Show top–right part of the matrix
- Ex. (110) – Show top–right part of the matrix and flip 90 degrees left
- Ex. (111) – Show top–right, flip 90 degrees left and flip horizontally
- Ex. (112) – Secondary diagonal scan (right)
- Ex. (113) – Secondary diagonal scan (left)
- Ex. (114) – Show bottom–right and flip horizontally
- Ex. (115) – Matrix flip vertical
- Ex. (116) – Matrix flip horizontal
- Ex. (117) – Sum values from elements of a matrix based on a map
- Ex. (118) – Add two matrices into a third
- Ex. (119) – Matrix multiplication with three for loops
- Ex. (120) – Matrix multiplication with two for loops
- Ex. (121) – Multiply specific elements of two matrices based on a map
- Ex. (122) – Different operations based on maps
- Ex. (123) – Different operations based on maps (SMC)
- Ex. (124) – Nested arrays
- Ex. (125) – Built-in Sin, Exp
- Ex. (126) – Max between two integer variables
- Ex. (127) – Max between two specific elements of an array
- Ex. (128) – Max over the values from an array
- Ex. (129) – Max over two array variables
- Ex. (130) – Random integers from 0 to 99 in an array
- Ex. (131) – Insert random values in the elements of a matrix
- Ex. (132) – Split string to integers by using a delimiter symbol
- Ex. (133) – Split string to array by using the "|" symbol
- Ex. (134) – Cascading built-in functions (split, join, length)
- Ex. (135) – Built-in sort function
- Ex. (136) – Making of a function
- Ex. (137) – Making of a function with more than one parameter
- Ex. (138) – Gauss summation - sum all from 0 to n
- Ex. (139) – Function calls to other functions
- Ex. (140) – A simple scanner to find the output distribution
- Ex. (141) – Function chaining - nested function calls
- Ex. (142) – Function composition
- Ex. (143) – Global variables and constants
- Ex. (144) – Pure and impure functions
- Ex. (145) – Procedures vs Functions
- Ex. (146) – Replacement for repeat loops with recursion
- Ex. (147) – Repeat string n times recursively
- Ex. (148) – Sum from 0 to n recursively
- Ex. (149) – Factorial from 0 to n
- Ex. (150) – Generate a sequence recursively
- Ex. (151) – Generate fibonacci recursively
- Ex. (152) – Sum all from array recursively
- Ex. (153) – Using an object constructor
- Ex. (154) – An object with three properties and a method (I)
- Ex. (155) – An object with three properties and a method (II)
- Ex. (156) – An object with complex methods
- Ex. (157) – Generate multiple objects with methods
- Ex. (158) – Object to JSON
- Ex. (159) – JSON to Object
- Ex. (160) – Anything to object to string
- Ex. (161) – Complex string to object (I) - direct nested access
- Ex. (162) – Complex string to object (II) - nested access by reference
- Ex. (163) – Make 1D array from parts of an object
- Ex. (164) – Make a matrix from parts of an object
- Ex. (165) – Strings to 1D arrays (I)
- Ex. (166) – Strings to 1D arrays (II)
- Ex. (167) – A 2D array loaded from string
- Ex. (168) – Load a matrix from a string by using two delimiters
- Ex. (169) – A function to correctly display a matrix
- Ex. (170) – A function to load and display matrices
- Ex. (171) – Load two matrices from strings and make the addition
- Ex. (172) – Function to swap diagonal of matrix
- Ex. (173) – Function to transpose a matrix
- Ex. (174) – Function for rotation of a matrix by 90 degrees
- Ex. (175) – Logical NOT
- Ex. (176) – Logical AND
- Ex. (177) – Logical OR
- Ex. (178) – Logical NAND (NOT AND)
- Ex. (179) – Logical NOR (NOT OR)
- Ex. (180) – Logical XOR
- Ex. (181) – Logical XNOR
- Ex. (182) – Logarithm of b in base a
- Ex. (183) – Smooth signal
- Ex. (184) – Greatest common divisor (GCD)
- Ex. (185) – Pseudo random generator
- Ex. (186) – Double brute force algorithm (DBFA)
- Ex. (187) – Alphabet detection
- Ex. (188) – Alphabet detection on matrices
- Ex. (189) – Low level native sort and eliminate duplicates (I)
- Ex. (190) – Low level native sort and eliminate duplicates (II)
- Ex. (191) – An optimized version of Bubble Sort
- Ex. (192) – Get all permutations of a given string (I)
- Ex. (193) – Get all permutations of a given string (II)
- Ex. (194) – Return an array with proportions (relative frequencies)
- Ex. (195) – Average, standard deviation and coefficient of variation
- Ex. (196) – Pearson correlation coefficient
- Ex. (197) – Vertical chart from the array with pre-declared values
- Ex. (198) – Vertical chart from array with random values at each run
- Ex. (199) – Shannon entropy
- Ex. (200) – Text (txt) to hexadecimal (hex)
- Ex. (201) – A txt to hex from array a to array b
- Ex. (202) – A txt to hex with in-place replacement
- Ex. (203) – A txt to hex in a function that receives an as argument
- Ex. (204) – Multiple functions for any to any conversion
- Ex. (205) – One function for any to any conversion and input type detection
- Ex. (206) – Base64 encoding function
- Ex. (207) – Spectral forecast for signals
- Ex. (208) – Logic gate functions applied to matrix elements
- Ex. (209) – The general logic gate based on a map
- Ex. (210) – Decompose a matrix into multiple matrices based on unique values
- Ex. (211) – Count islands over the matrix and show their location
- Ex. (212) – Count islands over the matrix and count the characters in each
- Ex. (213) – Count islands and calculate their percentage coverage
- Ex. (214) – Show similarities between two strings by sequence alignment
- Ex. (215) – Get complementary array by using random values
- Ex. (216) – Take the first 20% of the closest solutions (mutation/selection)
- Ex. (217) – Find complementary matrix by using stochastic means
- Ex. (218) – A two states Markov Chain simulator based on letters
- Ex. (219) – A two states Markov Chain simulator based on probability values
- Ex. (220) – Multiply a probability vector with a probability matrix n times
- Ex. (221) – A Markov Chain framework for simulation
- Ex. (222) – Base64 encoding and decoding via built-in functions
- Ex. (223) – Local storage
- Ex. (224) – Open files
- Ex. (225) – Charts
- Ex. (226) – The Graphical User Interface (GUI)
Paul A. Gagniuc. Coding Examples from Simple to Complex - Applications in Javascript. Synthesis Lectures on Computer Science. Springer International Publishing, 2024, pp. 1-240.