16 Jan 2017
This is how you find out if a number is prime in JavaScript:
function isPrime(n) {
var divisor = 2;
while (n > divisor) {
if (n % divisor == 0) {
return false;
}
else
divisor++;
}
return true;
}
var divisor = 2;
while (n > divisor) {
if (n % divisor == 0) {
return false;
}
else
divisor++;
}
return true;
}
Although it‘s not very efficient.
Replace All in Lisp
- (defun replace-all (string part replacement &key (test #'char=))
- "Returns a new string in which all the occurences of the part is replaced with replacement."
- (with-output-to-string (out)
- (loop with part-length = (length part)
- for old-pos = 0 then (+ pos part-length)
- for pos = (search part string
- :start2 old-pos
- :test test)
- do (write-string string out
- :start old-pos
- :end (or pos (length string)))
- when pos do (write-string replacement out)
- while pos)))
Nonetheless, does anyone know what for (i = 0; i <= 65555; i++); does?
