Skip to content

Commit

Permalink
Add javascript implementation for rp
Browse files Browse the repository at this point in the history
  • Loading branch information
ZoranPandovski committed Aug 14, 2017
1 parent e4de4a2 commit a2ab8e5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Russian_Peasant/Javascript/ZoranPandovski/rusian_peasant.js
@@ -0,0 +1,33 @@
'use strict'

const russian_peasant = function(num1,num2){
let x = num1,
y = num2,
sum = 0;
while(x > 0){
if(x % 2 == 1){
sum+=y;
}
x = x >> 1;
y = y << 1;
}

return sum;
}

//test

const assert = function(condition, message) {
if (!condition) {
message = message || "Assertion failed";
if (typeof Error !== "undefined") {
throw new Error(message);
}
throw message; // Fallback
}
}

const num1 = 12;
const num2 = 10;
const result = russian_peasant(num1,num2)
assert(result === 120);

0 comments on commit a2ab8e5

Please sign in to comment.