algorithm practice with javascript or c language