# An algorithm a day : How to check for a prime number in JavaScript

It is nearly guaranteed that at some time in your coding education you will be asked to write some type of function that involves prime numbers. It is a popular exercise in coding boot camps and sometimes even pop up in job interviews.

What are prime numbers?

A prime number is a natural number greater than 1 whose only factors are 1 and the number itself. That is, it can only be divided equally by 1 and itself.

Natural numbers are positive integers such as 1, 5, 201, 229999 etc. …

# An algorithm a day : Create a two-dimensional array from a single array

Today’s algorithm is one of freeCodeCamp’s challenges. You can find it in the Basic Algorithm Scripting chapter. For some reason they have nicknamed it chunky monkey..?!

We have to write a function that splits an array into groups. These groups are the length of a given size. Then we have to return these split groups as a two-dimensional array. The function takes two arguments. The first argument is the given array and the second argument is the given size.

So for example these two arguments:

`var array = ["My", "name", "is", "Marina", "Shemesh", "and", "I", "live", "in", "Israel"];var size…`

# An algorithm a day: Palindrome check in JavaScript

Palindromes are words or phrases and even numbers that read the same forwards and backwards. Short palindromes are quite common such as: civic, kayak, level, madam, noon, radar, rotor, and solos. They are also found in names like Eve, Hannah, Anna, Otto and Bob.

## Background

The word “palindrome” was created in the 17th century by the English playwright Ben Jonson from the Greek roots palin (πάλιν; “again”) and dromos (δρóμος; “way” or “direction”).

The Sator Square is probably the oldest palindrome known to us. A version was found on a wall in the city of Herculaneum that was buried in ash…

# An algorithm a day — the back story

I get SO irritated when adults (who really should know better) say that they never had to use functions, divide fractions or used algebra “in the real world”. They imply that maths is not that important because you really do not use it. Seriously!!

Maths do not only teach us to think on a rational and logical level but also makes us comfortable to think about abstract ideas. The high of level attention needed to understand mathematical theories can benefit us in many ways.

I recently completed a coding boot camp here in Israel and was just awestruck at how…

# An algorithm a day : Calculate the factorial of a number

## What is a factorial?

In maths, the factorial of a non-negative integer, is the product of all positive integers less than or equal to this non-negative integer.

The symbol for the factorial function is an exclamation mark after a number.

For example: 5!

So if you see something like 5! , you know that you will have to multiply the series of descending possitive integers.

For example:

5! = 5 * 4 * 3 * 2 * 1 = 120

and

4! = 4 * 3 * 2 * 1 = 24

## Integers or whole numbers or natural numbers?

If you google around a bit you will notice that the definition…

# The Rescue

This is the fifth of my Zichron Yaakov stories. I want to write a short story for every decade that my home town has existed. And since the town was established in 1883, I have still quite a few stories to write! The Rescue takes place in 1885 and is thus the ‘first’ Zichron Yaakov story. Note though I do not really write the stories in chronological order. …

# Simson and the sheep

A few months before Passover, a carefully selected member of the Kaduri clan start to look after the family’s sacrificial lamb. This lamb was well fed and watered often, given leisurely walks around the neighbourhood and just generally had its well being looked after. During its short stay with the Kaduri’s, the lamb was nearly treated like an Askenazi would treat the family’s dog.

The lamb, unlike an Askenazi ‘s family dog however, was however NOT allowed inside the house. Not to mention jumping on the couches. And its stay with the family was also not until the end of…

# The ghost of Sarah Aaronsohn

Testing, testing, 1 2 3. Can you hear me?”

Ariyah tried out her headpiece for her 10 am tour group. As always, she is more than 30 minutes early but she likes to be ready and prepared with all of the items on her checklist checked off.

And also, she had to escape the disapproval on her parents’ faces when they saw her wearing her tour guide dress again this morning. They had argued the same arguments over and over the last six months and a mere look from her parents will start the same script running through her head.

# The Yemen cobbler’s son — Part 2

Much to Yonathan’s surprise, Master Greenberg’s attitude towards the other students seemed to improve in the absence of David. He allowed the students a bit more time to copy his precious notes from the blackboard and even started to loosen the top shirt button underneath his tie.

One day he taught the older children about pi again. They had to figure it out by themselves by measuring the circumference and the radius of various circles. The teacher frowned down at Yonathan when Esther, the most clever girl in the school now, concluded that pi = 3.141. …

# The Yemen cobbler’s son

“I am sorry Master, but pi is equal to 3.141 not 2.5.”

Master Greenberg stretched himself as high as he can and looked down at the little twerp who dared to interfere in the morning’s math lesson. All the other children had their eyes downcast, copying furiously into their notebooks the sums from the blackboard. Their teacher liked to rub out what he written down within a couple of minutes. He felt that it not only encouraged their memory capacities but also kept the class quiet.

“Oh, is that so David HHHHamadi!. And where would a Yemen boy learn what…

## Marina Shemesh

My body may have left Africa but my soul does not agree. In Israel I have found love and the courage to do what I have always wanted to do: Write.

Get the Medium app