The reason I've refreshed my experiences with JS scripts executing was Hacker Cup organized by Facebook - there are no language restrictions in there, your scripts just has to know how to analyze given input and write the answers on the standard output. It is quite unpopular way of using & writing Javascript, so I will show few tips of command line in here.
Engines
There is such a JavaScript engine called Rhino. It is completely written in Java, open source, and very easy to use. It is managed by Mozilla, so you can find a lot of docs and tutorials on Mozilla's page.
Rhino has few additional functions eg for working with files (readFile()) or serializing objects (serialize()), which makes it useful in solving algorithmic problems in competitions like FBHC. Full list of all shell function can be found on Mozilla's page.
Each time you run Javascript scripts from command line, all the arguments you provide will be stored in global variable called 'arguments'. Enriched with this knowledge we can begin with some examples. This is my implementation of binarySearch algorithm:
Array.prototype.binSearch = function(element) { var element = parseInt(element, 10), left = 0, right = this.length-1, middle = ~~((left+right)/2), lastMiddle; while (parseInt(this[middle], 10) !== element) { if (lastMiddle === middle) { return null; //nothing found, break } if (parseInt(this[middle], 10) < element) left = middle++; else right = middle--; lastMiddle = middle; middle = Math.round((left+right)/2); } return middle; //index of found element } var MainFunction = function(args) { var a = readFile(args).split("\n"), arrayElement = a[0].split(" "), result; print("Array: "+arrayElement); for (var i=1, j=a.length;i < j;i++) { result = arrayElement.binSearch(a[i]); if (result) print("Element "+parseInt(a[i], 10)+" in on position nr "+result); else print("Element "+parseInt(a[i], 10)+" cannot be found in the array"); } }(arguments)As an input it takes filename with the elements of an array in first row and elements to find in that array in next rows, like this:
4 10 12 19 25 34 41 50 52 61 66 68 76 81 82 85 94 97 105 112 115 124 128 138 139 230 321 432 456 540 61 82 94 2 10 4 24 432Assuming that script file is called binSearch.js, data.txt is the file with input data, and both are in the same directory as Rhino, to run the script simply type
java -jar js.jar binSearch.js data.txtIdeone You can simply achieve the same effect using online tools\, without installing anything on your computer. Ideone, online IDE & debugging tool allows you to run your scripts using Rhino or SpiderMonkey, another Mozilla's JS engine, this one written in C. You can edit your scripts in realtime and provide different inputs on every run. Good luck in FBHC!
Its interesting to learn about the command line with the standard input and output.Thanks for sharing !
ReplyDeleteThank you for allowing me to read it, welcome to the next in a recent article. And thanks for sharing the nice article, keep posting or updating news article.
ReplyDeleteAWS Training in Bangalore
AWS training in sholinganallur
AWS training in Tambaram
AWS training in Velachery
nice blog
ReplyDeletedevops training in bangalore
hadoop training in bangalore
iot training in bangalore
machine learning training in bangalore
uipath training in bangalore
I have been searching for a useful post like this on salesforce course details, it is highly helpful for me and I have a great experience with this Salesforce Training who are providing certification and job assistance.
ReplyDeleteSalesforce admin training in Hyderabad
Thank you for this post.You most absolutely have built this blog website into something special.
ReplyDeletehadoop training in chennai
hadoop training in tambaram
salesforce training in chennai
salesforce training in tambaram
c and c plus plus course in chennai
c and c plus plus course in tambaram
machine learning training in chennai
machine learning training in tambaram
Thank you so much for sharing these amazing tips. I must say you are an incredible writer, I love the way that you describe the things. Please keep sharing.
ReplyDeletejava training in chennai
java training in velachery
aws training in chennai
aws training in velachery
python training in chennai
python training in velachery
selenium training in chennai
selenium training in velachery
Very good information. Its very useful for me. Waiting for furture blogs.
ReplyDeletedata science training in chennai
data science training in annanagar
android training in chennai
android training in annanagar
devops training in chennai
devops training in annanagar
artificial intelligence training in chennai
artificial intelligence training in annanagar
Very useful article. I suggest digital marketing course. It is in trend. There are job opportunities in this field.
ReplyDeleteGood job and thanks for sharing such a good blog You’re doing a great job. Keep it up !!seven Article with business,data science, D.m, health&fitness etc
ReplyDeleteGreat Article to Read. I was looking for this one. Thanks a lot. I .a suggestion for the Best Digital Marketing Course. If you want to enroll in Digital Marketing Course, Join 99 Digital Academy offers an affordable Digital Marketing Course. Click to Enroll Today.
ReplyDeleteBest Free Digital Marketing Seminar in Gurgaon.
Good Article. Thanks for posting this information. I was looking for this one. I have a suggestion for the Best Blogging Making Money sites. Rision Digital, Learn Tips Tricks to Succeed in Blogging and Earn Money.
ReplyDeleteThanks a lot for sharing kind of information. Your article provides such great information with good knowledge. Digital Marketing Training in Pune
ReplyDelete
ReplyDeleteThanks for sharing awesome blog,its very interested.I am also sharing
digital marketing traning institute in janakpuri you can click this link for more information.
Excellent post.I want to thank you for this informative read, I really appreciate sharing this great post.Keep up your work
ReplyDeleteThis is a wonderful piece of writing.It was really best blog. Thanking for sharing the blog which helps me more to understand. I am also sharing a post regarding packers and movers if anyone wants packers and movers in budget price please contact.
ReplyDeleteOnline courses in digital marketing Manage projects in your industry
ReplyDeleteDigitally tracking each worker's work per day, i.e., managing a construction project digitally. It takes just a few minutes a day to learn this method, then you can practice what you've learned. It is advisable to arrange the program chronologically, since the sessions are held chronologically.
digital marketing course in Bangalore
Job openings for digital marketers are abundant. As one of the market's leading providers of Digital Marketing Training Online, InventaTeq offers a wide selection of courses.
ReplyDeleteInventateq digital marketing training online
Learn more useful information from this blog.
ReplyDeletecriminal lawyers virginia
reckless driving in va
personal injury attorney fairfax va
yurtdışı kargo
ReplyDeleteresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
KWM8
Excellent information, I must say. Visiting your website is awesome and wonderful. I appreciate you giving this knowledge because I will find it beneficial.
ReplyDeleteLearn Best Software courses in Hyderabad