A while back, I saw some JavaScript where every var and function in the file was named after a type of fruit.
It look something like:
grapes.forEach(function(grape) {
if(grape < 10)
apple += orange;
});
We decided to name the unknown coder Fruitcake, although the code was running as expected.
The crazy part was having to read it all to see how it actually worked in order to just add a single new feature.
Has anyone else come across something like this?
Top comments (13)
Do entries for the International Obfuscated C Code Contest count?
In all seriousness, I've yet to see code that is more intentionally obtuse than some of the entries there (unless you count esolangs, in which case almost anything written in INTERCAL takes the cake in my opinion), with Toledo Nanochess being a particularly famous example, though my favorite example is the 1998 winner:
Which is a flight simulator for X11.
that is AWESOME
There have been a number of other interesting entries over the years. I can't find it right now, but I distinctly remember one older entry that was valid C89, FORTRAN77, and Bourne shell script which did the same thing in all three languages.
I think that one was Applin!
But there have been so many incredible ones over the years. This mini-Minecraft is a favorite of mine!
That code is pretty!
This hello world program in Brainf*ck confused me when I first saw it.
The Game of Life by Linus Akesson:
This code for a robot drive
var multiDArray = [[7,8], [3,4], [1,2], [5,6]];
multiDArray.sort(function(a,b){
return a[0] - b[0];
});
console.log(multiDArray); //returns [[1,2], [3,4], [5,6], [7,8]];
You want to perform an operation on each element inside an array, in ascending order.
The forEach() method allows you to perform a callback function on each element of the array, in ascending order.
var myArray = [9, 2, 7, 6, 8, 5, 3];
myArray.forEach(function(element, index, array){
console.log(element + ' element'); //returns 9, 2, 7, 6, 8, 5, 3
console.log(element + ' index '); //returns 0 ,1, 2, 3, 4, 5, 6
.....
});
You need an array of only the elements that meet some certain criteria.
var myArray = [9, 2, 7, 6, 8, 5, 3];
var elementsOver5 = myArray.filter(function(element){
return element > 5;
});
You want to reduce the elements into a single value.
var numArray = [1,2,3,4,5,6];
var reducedValue = numArray.reduce(function(prev, current){
return prev + current;
});
You need to find either the largest or smallest number in an array.
var numArray = [2,2,3,6,7,7,7,7,8,9];
console.log(Math.max.apply(null, numArray));
no , I haven't. But when programmers work as a team, they should write the variables,constants and etc with proper names , so that when their coworkers & even themselves see the code, they could grasp a slight understanding of what's happening inside the code. unfortunitely it's impossible to define a global standard for writing proper variable names
Now I'm hungry, thanks.
Yung code nung ka oofficemate ko