My JavaScript page
Hers is a collection of my JavaScript programs.
I'm doing my JavaScript stuff using node.js.
My JavaScript programs
Note: Most (if not all) programs use the utilities in js_utils.js.
- box_the_compass.js: Box the compass (Rosetta code)
- character_codes.js: Character codes (Rosetta code)
- combinations.js: Combinations of an array (Rosetta code)
- combinations_with_repetition.js: Combinations (with repetition/replacement) of an array (Rosetta code)
- combograms.html: HTML version of combograms.js. Files needed: combograms_inc.js, words_eng.js, words_swe.js
- combograms.js: Combograms, find what words can be created from a source word.
- count_occurrences_of_a_substring.js: Count occurrences of a substring (Rosetta code)
- day_of_the_week.js: Day of the week (Rosetta code)
- debruijn.js: de Bruijn sequences. As a HTML: debruijn.html
- deranged_anagrams.js: Anagrams/Deranged anagrams (Rosetta code)
- derangements.js: Permutations/Derangements (Rosetta code)
- dot_product.js: Dot product (Rosetta code)
- environment_variables.js: Environment variables (Rosetta code)
- equilibrium_index.js: Equilibrium index (Rosetta code)
- euler1.js: Euler #1
- euler2.js: Euler #2
- euler3.js: Euler #3
- euler4.js: Euler #4
- euler5.js: Euler #5
- euler6.js: Euler #6
- euler7.js: Euler #7
- euler8.js: Euler #8
- euler9.js: Euler #9
- euler10.js: Euler #10
- euler11.js: Euler #11
- euler12.js: Euler #12
- euler13.js: Euler #13
- euler14.js: Euler #14
- euler15.js: Euler #15
- euler16.js: Euler #16
- euler17.js: Euler #17
- euler18.js: Euler #18
- euler19.js: Euler #19
- euler20.js: Euler #20
- euler21.js: Euler #21
- euler22.js: Euler #22 (using euler22_names.txt
- euler23.js: Euler #23
- euler24.js: Euler #24
- euler25.js: Euler #25
- euler26.js: Euler #26
- euler27.js: Euler #27
- euler28.js: Euler #28
- euler29.js: Euler #29
- euler30.js: Euler #30
- euler31.js: Euler #31
- euler32.js: Euler #32
- euler33.js: Euler #33
- euler34.js: Euler #34
- euler35.js: Euler #35
- euler36.js: Euler #36
- euler37.js: Euler #37
- euler38.js: Euler #38
- euler39.js: Euler #39
- euler40.js: Euler #40
- euler41.js: Euler #41
- euler42.js: Euler #42 (using euler42_words.txt)
- euler43.js: Euler #43
- euler44.js: Euler #44
- euler45.js: Euler #45
- euler46.js: Euler #46
- euler47.js: Euler #47
- euler48.js: Euler #48
- euler49.js: Euler #49
- euler50.js: Euler #50
- evaluate_binomial_coefficients.js: Evaluate Binomial coefficients (Rosetta code)
- execute_a_system_command.js: Execute a system command (Rosetta code)
- factors_of_an_integer.js: Factors of an integer (Rosetta code)
- fibonacci_sequence.js: Fibonacci sequence (Rosetta code)
- find_the_missing_permutation.js: Find the missing permutation (Rosetta code
)
- fizzbuzz.js: FizzBuzz (Rosetta code)
- gray_code.js: Gray code (Rosetta code)
- greatest_common_divisor.js: Greatest Common Divisor (Rosetta code)
- hamming_numbers.js: Hamming numbers (Rosetta code)
- hash_from_two_arrays.js: Hash from two arrays (Rosetta code)
- js_utils.js: Utilities for most/all the JavaScript programs. The module exports the following functions. Note that the
<name>2
is often a chaining version of <name>
(except for range2
and timing2
>). The <name>N
is a BigInt version of <name>
.
- timing: time a function and prints the time
- timing2: run a function and returns the time (ms) and the output
- range: returns an array of [0,...n-1]
- range2: return an array of [1..n]
- range2N: return a BigInt array of [1..n]
- flatten: flattens an array
- flatten2: chain version of flatten
- sum: sum the numbers in an array
- sumN: BigInt version of sum
- sum2: chain version of sum
- prod: returns the product of an array of numbers
- prodN: BigInt version of prod
- prod2: chain version of prod
- prod2N: BigInt version prod2
- max: returns the maximum value in an array
- max2: chain version of max
- min: returns the minimum value in an array
- min2: chain version of min
- min2N: BigInt version of min2
- memoizer: memoizer (caching) a function
- last: returns the last element in an array
- butLast: returns the list of elements in an array except for the first
- num_to_list: returns the digits of a number
- num_to_list2: chain version of num_to_list
- fib: returns the n'th Fibonacci number
- fibN: BigInt version of fib
- prime_divisors: returns the prime factors of n
- factors: returns all the prime factors of n
- collect: convert an array of elements to a hash table
- collect2: chain version of collect
- all_divisors: the divisors of a number, except 1 and n
- all_divisors2: the divisors of anumber, including 1 and n
- all_divisors3: the divisors of anumber, including 1 but not n
- primes: all primes below n
- sieve: all primes below n using Erastothenes sieve
- isPrime: returns true of n is a prime number
- isPrimeCached: cached version of isPrime
- gcd: greatest common divisor
- lcm: lowest common multiplier
- factorial: factorial of a number
- factorial2: chain version of factorial
- factorialN: BigInt version of factorial
- subfactorial: subfactorial
- subfactorialN: BigInt version of subfactorial
- subfactorialNCached: Cached BigInt version of subfactorial
- dec2base: Convert a decimal number to a list of digits in base Base
- nlen: length of a number (number of base 10 digits), mathematical formula
- palindromic_number: is n a palindromic number
- palindromic_list: is the list palindromic
- is_pandigital: does the list of digits represent a pandigital number (1..9)
- transpose: transpse a matrix
- transpose2: chain version of transpose
- zip: zips arrays (aliased to transpose)
- zip2: chain version of zip (aliased to transpose2)
- all_diagonals: all diagonals of a sqaure matrix
- next_permutation: the next permutation of an array
- all_permutations: all permutations of an array
- partition: partition an array according to a function
- partition2: chain version of partition
- all_different: returns true if all elements in an array are distinct
- combinations: the combination of length k of an array
- combinations_with_replacement: the combination (with replacement/repetition) of length k of an array
- odometer: another name of combinations_with_replacement
- difference: find the elements that are in array a but not in array b
- numsortf: function for numeric sort
- powerset_array: returns the powerset (all subsets) of an array
- exclude_element: returns array a without the element e
- randomInt: returns a random integer from 0..max
- randomIntArray: returns an array of random integer from 0..max
- randomIntArrayNeg: returns an array of random integer from -max..max
- skip_undefined: skip all the undefined values in a matrix or an array
- skip_undefined2: chain version of skip_undefined
- skip_empty: skip all the empty lists in an array
- skip_empty2: chain version of skip_empty
- remove_duplicates: remove duplicates in an array
- remove_duplicates2: chain version of remove_duplicates
- dot_product: dot product of two arrays
- binomial: binomial (n over k)
- binomialN: BigInt version of binomial
- asum: accumulated sum
- asum2: chain version of asum
- scan: accumulate operations of an array
- scan2: chain version of scan
- argmax: return the index of the largest element in an array
- argmax2: chain version of argmax
- argmin: return the index of the smallest element in an array
- argmin2: chain version of argmin
- argmaxes: return all indices of the largest element(s) in an array
- argmaxes2: chain version of argmaxes
- argmins: return all indices of the smallest element(s) in an array
- argmins2: chain version of argmins
- random_element: return a random element from an array/string
- random_element2: chain version of random_element
- shuffle: shuffle an array
- shuffle2: chain version of shuffle
- create_matrix: creates a matrix of dimension r x c (with optinal initial value, default 0)
- print_matrix: prints a matrix
- print_matrix2: chain version of print_matrix
- random_matrix: creates a random matrix of dimension r x c with a max value
- matrix_mult: multiply two matrices
- matrix_mult2: chain version of matrix_mult
- matrix_element_op: element-wise operations on a matrix
- matrix_element_op2: chain version of matrix_element_op
- matrix_matrix_element_op: matrix-matrix element-wise operations
- matrix_matrix_element_op2: chain version of matrix_matrix_element_op
- zip_hash: return a hash table from arrays of keys and and values
- repeat: return the results of repeating a call to a function n times
- repeat2: chain version of repeat
- leap_year.js: Leap year (Rosetta code)
- letter_frequency.js: Letter frequency (Rosetta code)
- linear_congruential_generator.js: Linear congruential generator (Rosetta code)
- loop_over_multiple_arrays_simultaneously.js: Loop over multiple arrays simultaneously (Rosetta code)
- map_range.js: Map range (Rosetta code)
- matrix_element_wise_operations.js: Matrix element-wise operations (Rosetta code)
- matrix_multiplication.js: Matrix multiplication (Rosetta code)
- mcnuggets_problem.js: McNuggets problem (Rosetta code)
- monte_carlo_methods.js: Monte Carlo methods (Rosetta code)
- munchhausen_numbers.js: Münchhausen numbers (Rosetta code)
- one_dimensional_cellular_automata.js: One-dimensional cellular automata (Rosetta code)
- ordered_words.js: Ordered words (Rosetta code)
- pascals_triangle.js: Pascal's triangle (Rosetta code)
- perfect_numbers.js: Perfect numbers (Rosetta code)
- permutations.js: Permutations (Rosetta code)
- pick_random_element.js: Pick random element (Rosetta code)
- playing_cards.js: Plaing cards (Rosetta code)
- powerset.js: Power set (all subsets) of an array (Rosetta code)
- primality_by_trial_division.js: Primality by trial division (Rosetta code)
- queens.js: N-Queens problem
- read_test.js: Read test (reading a word list and match regular expressions (e.g. a.*b.*c.*d.*e.*, b.*c.*d.*e.*f.*. etc)
- remove_duplicate_elements.js: Remove duplicate elements (Rosetta code)
- run_euler.js: Run the Euler programs (1..50)
- run_euler2.js: Run the Euler programs (1..50) with statistics and check of correct answers
- search_a_list.js: Search a list (Rosetta code)
- send_more_money.js: SEND+MORE=MONEY
- solve_the_no_connection_puzzle.js: Solve the No connection puzle (Rosetta code)
- spelling_bee_solver.js: Spelling Bee solver
- text_processing_max_licenses_in_use.js: Text processing/Max licenses in use (Rosetta code)
- towers_of_hanoi.js: Towers of Hanoi (Rosetta code)
- transitive_closure.js: Transitive closure (pointer chasing)
- transpose_non_square_matrix.js: Transpose non-square matrix
- zebra.js: Zebra logic puzzle
Back to my homepage
Created by Hakan Kjellerstrand (hakank@gmail.com)